Cannot find module `pages/_document` after upgrading to Next.js 9
See original GitHub issueBug report
Describe the bug
After upgrading from version 8 to 9, the development server broke down with the following error.
To Reproduce
- Upgrade to Next.js 9
- Use custom
_document
component - Might be needed to reproduce: we use typescript in the app so in order to make use of the new default typescript support, we removed
@zeit/next-typescript
from package.json and@zeit/next-typescript/babel
from babel.config.js.
Expected behavior
yarn dev
should work as expected.
Actual behavior
yarn dev
fails with:
{ Error: Cannot find module 'app_dir/app/.next/server/static/development/pages/_document'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.loadComponents (app_dir/node_modules/next-server/dist/server/load-components.js:17:25)
at DevServer.findPageComponents (app_dir/node_modules/next-server/dist/server/next-server.js:298:40)
at DevServer.renderErrorToHTML (app_dir/node_modules/next-server/dist/server/next-server.js:362:35)
at DevServer.renderErrorToHTML (app_dir/node_modules/next/dist/server/next-dev-server.js:16:466)
at process.internalTickCallback (internal/process/next_tick.js:77:7) code: 'MODULE_NOT_FOUND' }
{ Error: Cannot find module 'app_dir/app/.next/server/static/development/pages/_document'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.loadComponents (app_dir/node_modules/next-server/dist/server/load-components.js:17:25)
at DevServer.findPageComponents (app_dir/node_modules/next-server/dist/server/next-server.js:298:40)
at DevServer.renderErrorToHTML (app_dir/node_modules/next-server/dist/server/next-server.js:362:35)
at DevServer.renderErrorToHTML (app_dir/node_modules/next/dist/server/next-dev-server.js:16:466) code: 'MODULE_NOT_FOUND' }
System information
- OS: macOS 10.14.5
- Browser Chrome 75
- Version of Next.js: 9.0.2
Additional context
_document.js
exists inapp_dir/app/
and was working fine before the upgrade. It handles some configuration and renders the page given to it.- Next’s root directory is set to
/app
, not/
. - When attempting to start the server with
yarn dev
, next doesn’t even generate.next/server
. The only generated directory is.next/cache
.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:9 (4 by maintainers)
Top Results From Across the Web
module-not-found - Next.js
The module you're trying to import is in a different directory. Make sure that the path you're importing refers to the right directory...
Read more >ERROR MODULE NOT FOUND whenever I try to run 'npm run ...
js file exist and it does. I was able to see the file on my browser and in my text editor. But when...
Read more >next-pwa - npm
After running next build , this will generate two files in your public : workbox-*.js and sw.js , which will automatically be served...
Read more >cannot find module [Node npm Error Solved] - freeCodeCamp
you're trying to import an item from a module you don't have installed in your project directory; you're importing some things from an...
Read more >r/nextjs - Reddit
NextJS throws random "Error: Cannot find module '. ... /Users/tylerkim/Documents/GitHub/scraft/scraft-app/.next/server/pages/_document.js ...
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
I’ve tried doing that and my observation has been that the Next build breaks with
Cannot find module [...]
whenever there’s a compile-time error in an already loaded file (type errors when transpiling typescript in this case). I’ll investigate this further. If this is the case, an improvement could be to make the error message more understandable - current one is rather misleading. Make it clear that modules cannot be loaded unless all compile-time errors are fixed, or perhaps even stop the build process at that point. What do you think?You’re adding
"@babel/preset-env",
in the babelrc, and as per the docsThese presets / plugins should not be added to your custom .babelrc.