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

Please verify that the package.json has a valid "main" entry #34844

Closed
1 task done
abhinavkumar940 opened this issue Feb 26, 2022 · 6 comments
Closed
1 task done

Please verify that the package.json has a valid "main" entry #34844

abhinavkumar940 opened this issue Feb 26, 2022 · 6 comments
Labels
bug Issue was opened via the bug report template. please add a complete reproduction The issue lacks information for further investigation

Comments

@abhinavkumar940
Copy link

Verify canary release

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

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101
    Binaries:
      Node: 16.13.0
      npm: 8.1.0
      Yarn: 1.22.17
      pnpm: N/A
    Relevant packages:
      next: 12.1.1-canary.4
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

2022-02-26T12:05:22.236Z	3b3580d4-559f-4f37-a322-c67420fc0f0f	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:93:18)
    at Object.5017 (/var/task/.next/server/pages/api/subscribe.js:23:39)
    at __webpack_require__ (/var/task/.next/server/webpack-api-runtime.js:25:42)
    at __webpack_exec__ (/var/task/.next/server/pages/api/subscribe.js:73:39)
    at /var/task/.next/server/pages/api/subscribe.js:74:28 {
  code: 'MODULE_NOT_FOUND',
  path: '/var/task/node_modules/next/package.json',
  requestPath: 'next'
}
RequestId: 3b3580d4-559f-4f37-a322-c67420fc0f0f Error: Runtime exited with error: exit status 1
Runtime.ExitError

Expected Behavior

The serverless function should execute successfully

To Reproduce

Call an API route

@abhinavkumar940 abhinavkumar940 added the bug Issue was opened via the bug report template. label Feb 26, 2022
@balazsorban44 balazsorban44 added the please add a complete reproduction The issue lacks information for further investigation label Feb 26, 2022
@balazsorban44
Copy link
Member

Could you please provide a reproduction

@abhinavkumar940
Copy link
Author

That's the problem @balazsorban44, it works fine on my local env. Even when I run it in PROD mode. But when I push that to vercel, only then I see this issue.

@balazsorban44
Copy link
Member

That's fine, if you can share a reproduction, I can deploy it myself. I'll need to verify the error myself so we can look more into this.

Are you maybe using type: "module" at your top-level package.json?

@abhinavkumar940
Copy link
Author

I have already checked for that but with no luck. Here is a minimal version

https://github.com/abhinavkumar940/nextjs-issue-reproduction

But weirdly the minimal version works on vercel, the original version doesn't. Although they both share the same package.json file.

@abhinavkumar940
Copy link
Author

Okay, was able to solve it but I have no idea what or how. I had this

import { NextApiRequest, NextApiResponse } from "next";

in my serverless function file /pages/api/subscribe.js (yes, a .js file)

I removed it and then it started working fine.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 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 Apr 1, 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. please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests

2 participants