Skip to content
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

import next from 'next' with getServerSideProps will break once deployed on Vercel #35873

Closed
1 task done
williamli opened this issue Apr 4, 2022 · 2 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@williamli
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Reproduction: https://github.com/vercel-support/76289-nextjs-getServerSideProps

When you have a page that uses getServerSideProps (SSR) and import a component that has import next from 'next', the page will cause a 500 error when deployed on Vercel.

In error log you will see Cannot find module '/var/task/node_modules/next/dist/server/next.js'.

[GET] /
21:03:32:86
2022-04-04T13:03:33.602Z	28928bb2-9a80-49f4-bc17-00e7d10231c2	ERROR	Error: Cannot find module '/var/task/node_modules/next/dist/server/next.js'. Please verify that the package.json has a valid "main" entry    at tryPackage (internal/modules/cjs/loader.js:321:19)    at Function.Module._findPath (internal/modules/cjs/loader.js:534:18)    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)    at Function.Module._load (internal/modules/cjs/loader.js:746:27)    at Module.require (internal/modules/cjs/loader.js:974:19)    at require (internal/modules/cjs/helpers.js:101:18)    at Object.580 (/var/task/.next/server/pages/index.js:64:39)    at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:42)    at __webpack_exec__ (/var/task/.next/server/pages/index.js:194:39)    at /var/task/.next/server/pages/index.js:195:66 {  code: 'MODULE_NOT_FOUND',  path: '/var/task/node_modules/next/package.json',  requestPath: 'next',  page: '/'}RequestId: 28928bb2-9a80-49f4-bc17-00e7d10231c2 Error: Runtime exited with error: exit status 1Runtime.ExitError

Problem will not affect pages that use getStaticProps or if you remove import next from 'next'.
Problem only occurs after deploying to Vercel, works fine in localhost.

Expected Behavior

Ideally, import next from 'next' can be ignored when running SSR, or a better error message can be considered.

To Reproduce

Reproduction: https://github.com/vercel-support/76289-nextjs-getServerSideProps.

See /components/chip.js' and /pages/index.js`.

@williamli williamli added the bug Issue was opened via the bug report template. label Apr 4, 2022
@balazsorban44
Copy link
Member

next is not meant to be imported this way. It is used in case of custom servers, which Vercel does not support.

Please refer to the docs: https://nextjs.org/docs/advanced-features/custom-server

@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

2 participants