babel-plugin-module-resolver icon indicating copy to clipboard operation
babel-plugin-module-resolver copied to clipboard

Problem with aliases

Open kacluk123 opened this issue 5 years ago • 5 comments
trafficstars

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.

kacluk123 avatar Oct 20 '20 13:10 kacluk123

I have the same error, Did you fix this?

patrickyyang avatar Dec 18 '20 10:12 patrickyyang

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

chunhoong avatar Mar 26 '21 16:03 chunhoong

This worked for me:

  • I removed node_modules
  • yarn install
  • pod install
  • run
watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* &&
 rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean --force &&
 npm install && npm start -- --reset-cache

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

MariusCatanoiu avatar Aug 25 '22 08:08 MariusCatanoiu

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?

Nantris avatar Sep 23 '22 01:09 Nantris

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

MariusCatanoiu avatar Sep 23 '22 06:09 MariusCatanoiu