Skip to content
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

BYONM: Dynamically importing CommonJS file from an npm package errors #21149

Open
bartlomieju opened this issue Nov 10, 2023 · 2 comments
Open
Labels
bug Something isn't working correctly node compat

Comments

@bartlomieju
Copy link
Member

$ deno run -A npm:create-next-app@latest next-app
$ cd next-app
$ deno run -A --unstable-byonm npm:next dev
error: Uncaught (in promise) ReferenceError: module is not defined
module.exports = nextConfig
^
    at file:///Users/ib/dev/next-app/next.config.js:6:1

Chaging module.exports = to export default fixes the problem.

@bartlomieju bartlomieju added bug Something isn't working correctly node compat labels Nov 10, 2023
@Cedar-81
Copy link

is this a problem that needs to be fixed on Denos end? (Still new to open source, just trying to understand how it could be fixed)

@dsherret
Copy link
Member

I disagree that this is a bug. The file is not located in an npm package. It's located at file:///Users/ib/dev/next-app/next.config.js, which means it is ESM. This can be fixed in next.config.js by changing:

module.exports = nextConfig;

To...

export default nextConfig;

...as Next.js loads this file via a dynamic import. We should update the error message to explain that module.exports = needs to be converted to ESM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

No branches or pull requests

3 participants