Leveraging Next.js with TypeScript and babel-plugin-module-resolver for simplified import aliases

I am currently in the process of setting up a Next.js project with typescript. Despite following multiple guides, I have encountered an issue concerning import aliases.

It's unclear whether this problem stems from my configuration or from Next.js itself.

I have tried implementing suggestions from various sources that address similar issues, but unfortunately, none have provided a solution:

One approach I attempted was tweaking Next.js' webpack configuration to resolve the issue (such as adding resolve.alias options directly to next.config.js), but this did not yield any positive results. It is worth mentioning that Next.js supposedly has built-in support for typescript now (resolve.extensions are well defined).

Next.js version 9.3.5

babel-plugin-module-resolver version 4.0.0

Included below are snippets from my tsconfig.json and .babelrc files for reference.

{
  "compilerOptions": {
    // compiler options here
  },
  // exclude and include paths here
}
{
  "presets": [ "next/babel" ],
  "plugins": [
    // module resolver plugin configuration here
  ]
}

Answer №1

Upon further reflection, I came to the realization that my objective was two-fold:

  • To manage typescript aliases
  • To utilize babel-plugin-inline-react-svg for importing SVGS

While the provided configuration successfully handles regular typescript imports, it does not support aliasing svg imports. Despite attempting to add the extension to module-resolver, I encountered no success.

Further investigation led me to discover an ongoing issue addressed at babel-plugin-inline-react-svg: https://example.com/issue123

Evidently, there exists a recognized compatibility challenge between babel-plugin-module-resolver and babel-plugin-inline-react-svg.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Formatting decimals with dots in Angular using the decimal pipe

When using the Angular(4) decimal pipe, I noticed that dots are shown with numbers that have more than 4 digits. However, when the number has exactly 4 digits, the dot is not displayed. For example: <td>USD {{amount| number: '1.2-2'}} < ...

Using a Javascript library within an Angular component: A comprehensive guide

I've been working on a Web-Client project that involves visualizing sensor data such as velocity and acceleration within a coordinate system. In order to display this coordinate system, I decided to use the graph.js library from https://github.com/dhu ...

React: A seamless method for rendering children to string on both client-side and server-side

Is there a way to convert children into a string in React 18/Next 13? I've read that using renderToString is not recommended on the client side in React, but I'm unsure how to render it on the server side. The documentation here provides an exa ...

Is the parameter rejecting the use of orderBy for 'startTime'?

Hey there! I'm currently working on an AngularJS project in TypeScript that involves integrating Google API to fetch Google Calendar events. The syntax for making a call is specified in the documentation available at: https://developers.google.com/goo ...

Radio buttons with multiple levels

Looking to implement a unique two-level radio button feature for a specific option only. Currently, I have written a logic that will display additional radio buttons under the 'Spring' option. However, the issue is that when it's selected, t ...

What is the best way to refine React Component's props with Typescript?

My setup involves utilizing two specific components: Test and Subtest. The main functionality of the Test component is to provide visual enhancements and pass a portion of its props down to the Subtest component. Some props in the Subtest component are des ...

Ways to determine if the keys of an object are present in an array, filtered by the array key

Working on an Angular 2 Ionic application and I'm wondering if there's a straightforward way to filter individuals by age in a specific array and then verify if any key in another object matches the name of a person in the array, returning a bool ...

Issue with Select component in Material UI v5 where changing the border to none does not function as expected

I am currently utilizing NextJs with material ui v5 and attempting to set {border: none} for the Select component from mui. However, I am facing issues as it does not seem to work. To tackle this problem, I have decided to apply the sx prop object, conside ...

Unused Angular conditional provider found in final production bundle

Looking for a way to dynamically replace a service with a mock service based on an environment variable? I've been using the ?-operator in the provider section of my module like this: @NgModule({ imports: [ ... ], providers: [ ... en ...

Using TypeScript to style React components with the latest version of Material UI, version

Styled typography component accepts all the default typography props. When I include <ExtraProps> between styled() and the style, it also allows for extra props. const StyledTypography = styled(Typography)<ExtraProps>({}) My query is: when I r ...

Filtering Deno tests by filename: A step-by-step guide

How can I selectively run Deno tests based on their filenames? Consider the following test files: number_1_test.ts number_2_test.ts string_test.ts If I want to only run tests with filenames starting with number*, I am unable to use either of these comma ...

Hey everyone, I'm struggling with the latest update of Next.js (version 14). Can anyone confirm if it still supports API routes or if they've removed that feature?

While attempting to create an API in the updated Next.js version (14), I encountered a roadblock. Despite setting up a folder (api) and a file (hello.js) for the API code, it seems that the new version does not support this feature. I even have a screensho ...

[next-auth][error][adapter_error_getUserByAccount]; Unable to access attributes of an unspecified item (viewing 'findUnique')

Currently, I am developing a sign up page that integrates with three popular providers (Twitter, Facebook, and Instagram) using next-auth in combination with Prisma and MongoDB. However, I have encountered an issue while attempting to sign up using any of ...

Exploring the Benefits of Utilizing the tslint.json Configuration File in an Angular 6 Project

https://i.stack.imgur.com/j5TCX.png Can you explain the importance of having two tslint.json files, one inside the src folder and one inside the project folder? What sets them apart from each other? ...

I'm receiving a 404 error on my API route in next.js - what could be causing this

What could be causing the error message "GET http://localhost:3000/api/db/getRideTypes 404 (Not Found)" when attempting to fetch data from the sanity client? Here is a snippet of code from Rideselector.js: //"use client"; import Image from &apo ...

Navigating through each element of an array individually by using the onClick function in React

I'm currently working on a project that involves creating a button to cycle through different themes when pressed. The goal is for the button to display each theme in sequence and loop back to the beginning after reaching the last one. I've imple ...

The combination of UseState and useContext in React Typescript may lead to compatibility issues

I attempted to integrate the context API with the useState hook but encountered difficulties when using TypeScript. First, let's create App.tsx: const App = () => { const [exampleId, updateExampleId] = useState(0); return ( <div> ...

Is Typescript generating error TS2411 within its own Typescript module?

After transitioning to using @types in Typescript 2.0, I executed npm i -S typescript @types/typescript to ensure everything was set up correctly with typescript. However, whenever I run tsc on my project and exclude "node_modules", I encounter the same e ...

What methods can I use to combine existing types and create a brand new one?

Is there a way to combine existing types to create a new type in TypeScript? `export type Align = 'center' | 'left' | 'right' export type Breakpoints = ‘sm’ | ‘md’` I want to merge the Align and Breakpoints types to ...

When implementing `redux-observable` with NextJS, the `HYDRATION` action may not properly receive the server payload

Packages: redux-observable@2.0.0-rc.2 rxjs latest universal-rxjs-ajax dev branch next-redux-wrapper latest next.js latest I am working on a simple Page with getStaticProps: export const getStaticProps = wrapper.getStaticProps((store) => async (ctx) =& ...