-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nextjs 15: Importing git modules issue - 'Module not found: Can't resolve 'package-name' #69926
Comments
Also fails with Nextjs 14.2.9 and React 18, same error indicating possible issue with Webpack:
I have tried using ts-load with 'special' webpack config as mentioned here Note - all repos used to reproduce issue here are public (although I would normally use a private repo). |
I realised after a while that the packages installed from git are not compiled by npm/pnpm/yarn which was causing some issues. Once compiled, it feels the
What I did then is copy the code from git into the main project and after that I found that React/Nextjs were having issues in transferring data and functions between server and client components. Fair enough but the error messages with the repo were completely absent. Also, this wasn't the fault of the imported git library as such. I am also not clear why the issues between passing data/functions between server/client components wasn't raised before as the git library is a wrapper so all underlying types and their serialization properties were the same before and after the library. It is worth mentioning that next build worked at every step of the way without reporting any issues. So I fixed the newly discovered issues between server/client components and then tried again to import the library from git instead of having the local code. But then I received again the error above with path (compiled file) not found. So I guess there must be more errors that are hidden by the nextjs/react compilation process. Is there a way to get more detailed output so to understand why exactly nextjs build/webpack/react 19 are failing? I tried NODE_OPTIONS='--inspect' but it doesn't give anything more. |
I have now realised that there is a further discrepancy in importing packages from git with nextjs:
I have tried adding "stuff" to next.config.mjs based on various posts with similar issues but none of this works - e.g I now have transpilePackages: ["simple-package"],
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.module.rules.push({
test: /\.(ts)x?$/, // Just `tsx?` file only
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
experimentalWatchApi: true,
onlyCompileBundledFiles: true,
},
},
],
});
// Ensure proper resolution of .mjs files
config.resolve = {
...config.resolve,
extensions: [".js", ".jsx", ".ts", ".tsx", ".mjs"],
alias: {
...config.resolve.alias,
"simple-package": path.resolve(__dirname, "node_modules", "simple-package"),
},
};
// Clear cache if necessary
if (dev) {
config.cache = false;
} Also, the folder which Webpack raises with TypeError does not exist with next dev; node_modules contains the package and it is compiled from ts to js correctly too. I wonder what is the difference in the webpack options used between next dev and next build/start? |
Having the same issue when trying to use some git repo as dependency.
|
This comment has been minimized.
This comment has been minimized.
got the same issue too when using pnpm |
effecting both the latest and canary with the following dependency
|
Link to the code that reproduces this issue
https://github.com/moltco/simple-consumer-2
To Reproduce
git clone https://github.com/moltco/simple-package
git clone https://github.com/moltco/simple-consumer-2
pnpm install && pnpm build
(orpnpm dev
then visit http://localhost:3000/ to get it to compile)'Module not found: Can't resolve 'simple-package'
Current vs. Expected behavior
Expected: import to work
Current: typescript intellisense etc works but cannot compile.
Provide environment information
Which area(s) are affected? (Select all that apply)
Module Resolution
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
I tested agains canary 15.0.0-canary.56 and 15.0.0-canary.148 -> both seem to suffer from the same issue
The text was updated successfully, but these errors were encountered: