ncc icon indicating copy to clipboard operation
ncc copied to clipboard

Module not found for paths in jsconfig.json

Open neeppy opened this issue 4 years ago • 5 comments

Context I have a NextJS application (running JS, not TS) with a jsconfig.json file used to map some module aliases (@utils for example). Everything works fine there! However, we need to manually run some NodeJS scripts to alter the database. I decided to go with ncc because I thought it would allow me to reuse the NextJS code (I'm talking about server-side code, obviously). However, here comes the issue: whenever we attempt to import a module from our NextJS app, we get a Module not found error if the import tree includes an alias (seems like ncc ignores jsconfig.json).

Expected Result TakecompilerOptions.paths from jsconfig.json into account when building the app.

The docs haven't been too useful about this issue.

neeppy avatar Jan 13 '22 13:01 neeppy

Take a look at #587 and #821

styfle avatar Jan 13 '22 20:01 styfle

Thank you for your reply, @styfle! Unfortunately, I already stumbled upon those issues before posting my own and they couldn't help me find a resolution.

To be more clear about my issue, I'm trying to create a CLI module alongside my NextJS app that would allow me to perform certain actions manually from a terminal. However, as of now, I'm stuck with using plain node myscript.js to run anything, meaning I can't really make use of code previously written. ncc is the closest thing I could find, but because I have path aliases defined for the Next app, it still makes it unusable in my usecase.

neeppy avatar Jan 20 '22 23:01 neeppy

I am also facing the same issue, in SignInForm.jsx I imported import signIn from '@myFirebase/auth/SignIn'; and it seems vercel doesn't understand custom paths

./app/sign-in/SignInForm.jsx
--
14:12:28.702 | Module not found: Can't resolve '@myFirebase/auth/SignIn

This is my jsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@myFirebase/*": ["components/firebase/*"],
      "@components/*": ["components/*"],
      "@styles/*": ["styles/*"]
    }
  }
}

goheesheng avatar Jun 13 '23 06:06 goheesheng

Two year later, but in case it happens for anyone else, in my case it was Git which lowercased one of my file paths. I found this: https://vercel.com/support/articles/how-do-i-resolve-a-module-not-found-error which suggested to set it not to ignore casings with git config core.ignorecase false.

Okeke-Divine avatar Apr 17 '24 10:04 Okeke-Divine

this is still not working in my case. { "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } } causes import issues if I use @/something

auspy avatar May 07 '24 08:05 auspy