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.

Set the node_modules as symlink in 9.5.2, the build process fails

See original GitHub issue

Bug report

Describe the bug

Set the node_modules as symlink, in v9.5.2, the build process fail while v9.4.4 is success.

The error messages:

yarn run v1.22.4
$ next build
info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data
[=   ] info  - Generating static pages (0/2)
Error occurred prerendering page "/404". Read more: https://err.sh/next.js/prerender-error
Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Z (/Users/Hank.Lin/playground/next-app/.next/server/pages/_document.js:177:404)
    at module.exports.BdB7.exports.useContext (/Users/Hank.Lin/playground/next-app/.next/server/pages/_document.js:182:261)
    at Html (/Users/Hank.Lin/playground/next-app/.next/server/pages/_document.js:773:29)
    at d (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:36:498)
    at $a (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:39:16)
    at a.b.render (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:44:476)
    at a.b.read (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:44:18)
    at renderToStaticMarkup (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:54:462)
    at renderDocument (/Users/Hank.Lin/playground/node_modules/next/dist/next-server/server/render.js:3:624)
    at renderToHTML (/Users/Hank.Lin/playground/node_modules/next/dist/next-server/server/render.js:50:72)

Error occurred prerendering page "/". Read more: https://err.sh/next.js/prerender-error
Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Z (/Users/Hank.Lin/playground/next-app/.next/server/pages/_document.js:177:404)
    at module.exports.BdB7.exports.useContext (/Users/Hank.Lin/playground/next-app/.next/server/pages/_document.js:182:261)
    at Html (/Users/Hank.Lin/playground/next-app/.next/server/pages/_document.js:773:29)
    at d (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:36:498)
    at $a (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:39:16)
    at a.b.render (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:44:476)
    at a.b.read (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:44:18)
    at renderToStaticMarkup (/Users/Hank.Lin/playground/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:54:462)
    at renderDocument (/Users/Hank.Lin/playground/node_modules/next/dist/next-server/server/render.js:3:624)
    at renderToHTML (/Users/Hank.Lin/playground/node_modules/next/dist/next-server/server/render.js:50:72)
info  - Generating static pages (2/2)

> Build error occurred
Error: Export encountered errors on following paths:
	/
	/404
    at exportApp (/Users/Hank.Lin/playground/node_modules/next/dist/export/index.js:24:1103)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async build (/Users/Hank.Lin/playground/node_modules/next/dist/build/index.js:37:212)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

To Reproduce

  1. yarn create next-app
  2. rm -rf node_modules & ln -s some_path/node_modules
  3. yarn & yarn build

System information

  • OS: mac os
  • Version of Next.js: 9.5.2
  • Version of Node.js: 12.16.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jyunhanlincommented, Sep 8, 2020

Investigation update:

When set the node_modules as symlink, and the run yarn build, the .next/server/pages/_document.js contained the react.producion.min.js

Refer to https://github.com/facebook/react/issues/16029#issuecomment-570912067 Set the webpack config in next.confg.js

config.externals = [
  ...config.externals,
  {
    react: {
      root: 'React',
      commonjs2: 'react',
      commonjs: 'react',
      amd: 'react'
    },
    'react-dom': {
      root: 'ReactDOM',
      commonjs2: 'react-dom',
      commonjs: 'react-dom',
      amd: 'react-dom'
    }
  }
]

The build process is success.

The next.js version is 9.5.4-canary.5

1reaction
TianyiLicommented, Aug 21, 2020

Same here, but the error is different.

image

For the production build is success, but when starting the service i got this error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm install fails when node_modules is a symlink #10013
The reason for relying on a symlinked node_modules is that I sync my development folder over multiple machines, but symlink all huge folders, ......
Read more >
Having project_name/node_modules as a symlink?
Still looking into it, but this does seem to be working for me. The steps to try it would be 1) remove node_modules...
Read more >
The magic behind npm link - Medium
Node.js has a very simple module loading strategy. ... npm creates a symbolic link from your “global node_modules” directory to the local module's...
Read more >
EasyBuild v4.6.2 documentation (release 20221021.0)
The latest version of EasyBuild provides support for building and installing 2,798 different software packages, including 37 different (compiler) toolchains ...
Read more >
npm-link
First, npm link in a package folder with no arguments will create a symlink in the global folder {prefix}/lib/node_modules/<package> that links to the...
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