Skip to content

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

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

Closed
jyunhanlin opened this issue Aug 18, 2020 · 5 comments
Closed

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

jyunhanlin opened this issue Aug 18, 2020 · 5 comments
Labels
good first issue Easy to fix issues, good for newcomers
Milestone

Comments

@jyunhanlin
Copy link
Contributor

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
@TianyiLi
Copy link

Same here, but the error is different.

image

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

@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers kind: bug labels Aug 21, 2020
@timneutkens timneutkens added this to the backlog milestone Aug 21, 2020
@timneutkens
Copy link
Member

Feel free to investigate the issue @jyunhanlin

@jyunhanlin
Copy link
Contributor Author

jyunhanlin commented Sep 5, 2020

In next.js/packages/next/pages/_document.tsx, the useContext in Html and Main component is breaking the Rules of Hooks when set the node_modules as symlink. (also happened in 9.5.3)

@jyunhanlin
Copy link
Contributor Author

jyunhanlin commented 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 facebook/react#16029 (comment)
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

@Timer Timer reopened this Sep 8, 2020
@Timer Timer closed this as completed Sep 8, 2020
@Timer Timer modified the milestones: backlog, iteration 9 Sep 8, 2020
@balazsorban44
Copy link
Member

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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants