question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next build fails with ERR_MODULE_NOT_FOUND - Works in 11.x but not in 12.x

See original GitHub issue

What version of Next.js are you using?

12.0.4

What version of Node.js are you using?

17.0.1

What browser are you using?

Chrome

What operating system are you using?

Windows

How are you deploying your application?

next build

Describe the Bug

next build erros with a Module not found

info  - Creating an optimized production build  
info  - Compiled successfully

> Build error occurred
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\PROG\Issues\issues-nextjs-deepkit\node_modules\@deepkit\type\dist\esm\src\types' imported from C:\PROG\Issues\issues-nextjs-deepkit\node_modules\@deepkit
\type\dist\esm\index.js
    at new NodeError (node:internal/errors:371:5)
    at finalizeResolution (node:internal/modules/esm/resolve:394:11)
    at moduleResolve (node:internal/modules/esm/resolve:915:10)
    at defaultResolve (node:internal/modules/esm/resolve:1005:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:475:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:245:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  type: 'Error',
  code: 'ERR_MODULE_NOT_FOUND'
}

Expected Behavior

A proper successful build.

To Reproduce

I created a repo with 2 branches and steps.

next 11.x branch : Building correctly next 12.x branch : Building fails

https://github.com/lionelhorn/issues-nextjs-deepkit

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
balazsorban44commented, Nov 30, 2021

Adding this to next.config.js

experimental: {
  esmExternals: false,
},

Fixes this temporarily.

Seems to be related to https://nextjs.org/blog/next-12#es-modules-support-and-url-imports

I’ll try to look more into this.

Here is a related thread: https://github.com/vercel/next.js/discussions/27876

0reactions
balazsorban44commented, Jan 27, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

next build fails with webpack error #25276 - GitHub
When attempting to do a build with next build I get the following error. With next 10.2.0, the error does not appear.
Read more >
NextJS12 production build errors on module not found
I don't think this is an actual error. This happened to me once. Just try deleting .next folder first and then run npm...
Read more >
Errors | Node.js v19.3.0 Documentation
This will not work because the callback function passed to fs.readFile() is called asynchronously. By the time the callback has been called, the...
Read more >
Incremental Static Regeneration - Data Fetching - Next.js
Next.js allows you to create or update static pages after you've built your site. Incremental Static Regeneration (ISR) enables you to use static-generation ......
Read more >
React Storybook deploy fails during Webpack build - Support
The weird thing is deploying this Storybook used to work just fine. ... Typescript “module not found” error during one ill-fated Netlify deploy,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found