vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.13k stars 287 forks source link

Module not found for paths in jsconfig.json #847

Open neeppy opened 2 years ago

neeppy commented 2 years ago

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.

styfle commented 2 years ago

Take a look at #587 and #821

neeppy commented 2 years ago

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.

goheesheng commented 1 year ago

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/*"]
    }
  }
}
Okeke-Divine commented 5 months ago

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.

auspy commented 4 months ago

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