Module not found: Can't resolve 'builtin-modules'
See original GitHub issuemdx-bundler
version: 3.1.2node
version: 14.15.4yarn
version: 1.22.10next
version: 10.1.3 & 10.0.9
Relevant code or config
// config for 10.1.3
module.exports = {
future: {
webpack5: true,
},
reactStrictMode: true,
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
if (!isServer) {
// https://github.com/vercel/next.js/issues/7755
config.resolve = {
...config.resolve,
fallback: {
...config.resolve.fallback,
// Don't load this on the client.
fs: false,
},
}
}
return config
},
}
// config for 10.0.9
module.exports = {
reactStrictMode: true,
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
if (!isServer) {
// https://github.com/vercel/next.js/issues/7755
config.node = {
// Don't load this on the client.
fs: 'empty',
}
}
return config
},
}
What you did:
Following along with the documentation and after installing mdx-bundler
and trying to run the dev sever for next
I get the below output. The other screen shot is the output from executing yarn build
I get the same using either version and configuration of next
.
What happened:
Reproduction repository:
https://github.com/rockchalkwushock/codybrunner.dev/pull/84
Problem description:
It seems as though if running either webpack@4
or opting in for webpack@5
in next
there is an issue with the resolving of esm
imports.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located under ...
Read more >Module not found: Error: Can't resolve 'path' [Solved]
The error "Module not found: Error: Can't resolve 'path'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >builtin-modules - npm
List of the Node.js builtin modules. Latest version: 3.3.0, last published: 8 months ago. Start using builtin-modules in your project by ...
Read more >module-not-found - Next.js
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies;...
Read more >can't resolve 'fs' import trace for requested module: - You.com
My guess is you are trying to do import {DR_LINK} from "../main"; on client side from a server file. The clue is the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@IanMitchell another solution (although I would not recommend it) is to do the following in your
next.config.js
After a lot of reading this afternoon the underlying problem is that somewhere we are accidentally shipping node based code in the client bundle. I found the following resource from Vercel for seeing what is bundled for the client. I haven’t begun using it yet to try and debug where I am accidentally shipping those node packages yet.
@IanMitchell sorry just now seeing this.
I do believe I figured out what the problem is surrounding that error message. In my project all third-party service code lives in
lib/
and those files are export from theindex.ts
like so:The service’s code is then imported as:
So the
mdx
service was exported like that and whenever I added another service and exported it in the same manner this error message would arise:Module not found: Can't resolve 'builtin-modules'
To fix this I simply removed the
export * from './mdx'
and changed the import for that service to be:I ran into a similar issue when using
firebase-admin
and stumbled upon a note I left myself months ago about…at least why this was an issue withfirebase-admin
:For further reference it seems as though this is a
webpack
bug that was solved some time ago (not sure what release it was packaged in).next
is usingwebpack@4.44.1
I am yet to figure out which version ofwebpack@5
is being used but you can see here were they switch the loading if you opt-in.My assumption is that not
mdx-bundler
butxdm || esbuild (the more likely culprit)
has some internal code that is clashing with the other modules when exporting andwebpack
no likey. My understanding of the ESM import/exports is not the greatest, although I did see @kentcdodds released a post recently on this that I need to take the time to read.Hope this helps you out 🎉 🥂