-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Cannot find module
error when package directory name ends with next
#34000
Comments
Cannot find module
error when package directory is named next
Cannot find module
error when package directory name ends with next
This issue is also showing up when a package is published to npm. If the package name ends with |
Hi, I just looked into this, but already am stuck on the steps 4.
CORRECTION Apologies, I was looking at the URL Thank you for the clear reproduction. 🙏 |
For what it's worth, I had a similar use case when I wanted a way to work on a package with Next.js' live reload, within an example app. I came up with this solution over at (That repo is being converted into a monorepo now, for similar goals, creating framework-specific packages.) |
Having another look, I noticed a few issues: I noticed you are using Furthermore, your Have a look at the Node.js documentation for more context: https://nodejs.org/api/packages.html Corporating those changes, I only needed a small additional change to get your setup working. Somehow this line So there is still a high chance of a bug here, just wanted to share what I've found so far. |
The issue is likely related to this line: next.js/packages/next/build/webpack-config.ts Line 880 in 7be6359
Poking around with it locally, I could get one of the cases working. |
Thanks for engaging!
I'll consider publishing my module as ESM only, but I vaguely recall running into some issues because of that. Regardless, my expectation is that Next.js should be able to
This is changing the semantics of the package. I do want to export
That sounds plausible! It really is based on the directory name, so some Webpack code resolution settings seem like the likely culprit. |
Understandable, it was just an observation. The bug is noted, I'm now trying to create a fix/test for this so we won't regress.
Do you have an npm package example that also produces that issue? I'm trying to reproduce it as well. (I created this one, but it worked: https://www.npmjs.com/package/@balazsorban/pkg-34000-next) To be more precise, the issue will happen when |
Don't have an npm package handy, but I did run into it while developing my application. I'll try to make a repro. |
Yeah, I can try too, I was just curious. Thanks for reporting! |
This is no longer happening on the latest! |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Run
next info
(available from version 12.0.8 and up)What version of Next.js are you using?
12.0.10
What version of Node.js are you using?
17.0.1
What browser are you using?
Chrome
What operating system are you using?
macOS Monterey 12.0.1
How are you deploying your application?
Local
Describe the Bug
Next.js is unable to find a module in a package even though it exists. This only shows up when the parent directory's name ends with
next
.I'm trying to create an npm package that other Next.js developers can import and use in their codebase.
My package is called
repro
, but the directory it lives in is callednext
. The reason I'm doing this is that I'm developing packages for multiple frameworks (so you can imagine having directories callednext
,remix
,express
, etc.). This directory then has anexamples/basic
directory within it which is a Next.js application. This application depends on the package via anpm install ../..
, which creates a"repro": "file:../.."
entry within itsdependencies
.When I try to run my
examples/basic
Next.js application, API routes are unable to import the code from my package. Instead, they fail with a module resolution error that looks like the image below.This happens if the parent directory is named
next
or has a name that ends with it, such asfoo-next
. If the parent directory is named something else, likefoo
ornext-foo
, this doesn't happen.Expected Behavior
I expect the code to compile without any issues.
To Reproduce
Reproduction with steps: https://github.com/athyuttamre/next-module-reproduction
The text was updated successfully, but these errors were encountered: