tleunen / babel-plugin-module-resolver

Custom module resolver plugin for Babel
MIT License
3.45k stars 203 forks source link

Problem with aliases #412

Open kacluk123 opened 3 years ago

kacluk123 commented 3 years ago

Babel resolver does not work in my next.js project

My .babelrc file

    {
      "presets": ["next/babel"],
      "plugins": [
        [
          "module-resolver",
          {
            "root": ["./"],
            "alias": {
              "@components": "./src/components",
            }
          }
        ],
        ["styled-components", { "ssr": true }]
      ]
    }

My tsconfig

    "paths": {
      "@components/*": ["./src/components/*"],
      "baseUrl": "."
     },

And when im trying to use it like that

    import Login from '@components/login'

    export default Login

vscode throws an error

Cannot find module '@components/login' or its corresponding type declarations.

patrickyyang commented 3 years ago

I have the same error, Did you fix this?

chunhoong commented 3 years ago

Assume everything is correct- Perhaps try to restart TypeScript language server in vscode?

MariusCatanoiu commented 1 year ago

This worked for me:

And I use it like this import { AppStateHandler, FocusListeners, LoadingContainer } from '@components';

Nantris commented 1 year ago

This is TS2307. @kacluk123 it's good practice to include the error code, not just the text.

Anybody know how to fix it?

@MariusCatanoiu can you clarify what you mean? You were able to get this working?

MariusCatanoiu commented 1 year ago

This is TS2307. @kacluk123 it's good practice to include the error code, not just the text.

Anybody know how to fix it?

@MariusCatanoiu can you clarify what you mean? You were able to get this working?

I updated the previous comment