0

I'm migrating my Next.js project from Babel compiler to Next.js SWC-powered compiler - https://nextjs.org/docs/architecture/nextjs-compiler

After the necessary changes the app itself works fine, however inside the app there are imports that were powered by Babel's Module Resolver plugin - https://github.com/tleunen/babel-plugin-module-resolver

The .babelrc config itself is defining these aliases like this -

    [
      "module-resolver",
      {
        "root": ["./"],
        "alias": {
          "~": "./src",
          "~~": "./"
        }
      }
    ],

but ESLint cannot resolve the imports defined either with ~ or ~~ e.g. -

Unable to resolve path to module '~/services/my-service'. eslintimport/no-unresolved

Inside .eslintrc there's import/resolver settings (Babel import resolver removed - https://github.com/tleunen/eslint-import-resolver-babel-module) e.g. -

  settings: {
    'import/resolver': {
      'node': {
      // 'babel-module': {
      //   'extensions': ['.js', '.jsx', '.ts', '.tsx']
      // },
        'extensions': ['.js', '.ts', '.tsx']
      }
    }
  }

Not sure what is missing in this setup. How does SWC knows the correct aliases ~ or ~~ and what should be done to make ESLint happy again?

Kosmetika
  • 20,774
  • 37
  • 108
  • 172
  • Can you post your `.eslintrc` and `tsconfig.json`? Also, what's your Next.js version? – Igor Danchenko Jun 30 '23 at 14:19
  • solved by installing https://github.com/import-js/eslint-import-resolver-typescript instead of https://github.com/tleunen/eslint-import-resolver-babel-module – Kosmetika Jun 30 '23 at 14:33

0 Answers0