API function error when Nextjs app has package type=module
See original GitHub issueVerify 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.4.0: Fri Mar 18 00:47:26 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101
Binaries:
Node: 16.15.0
npm: 8.5.5
Yarn: 1.22.15
pnpm: 6.11.0
Relevant packages:
next: 12.1.5
react: 18.1.0
react-dom: 18.1.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
branch trigger
Describe the Bug
Getting error when calling an api route when my package.json type=module
2022-05-14T00:47:32.805Z undefined ERROR ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///var/task/___next_launcher.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
at async getListener (/var/task/___vc/__launcher.js:37:11)
RequestId: 53046e6c-3224-48d2-9428-1db2456069c2 Error: Runtime exited with error: exit status 1
Runtime.ExitError
Expected Behavior
Run function without error
To Reproduce
create api function with .ts in a nextjs app with it’s package.json type=module
deploy function to vercel
trigger production function
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Issue with backend-side ES6 imports with "type":"module" with ...
Describe the Bug. I have an Express.js server that sets up Next.js, and I want to use ES6 modules with my backend. My...
Read more >ERR_REQUIRE_ESM and Package.json error on Next.js. after ...
This error is fixed when removing "type": "module" from package.json . Support for using ESM-only node_modules is still fine.
Read more >module-not-found - Next.js
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies;...
Read more >Solved: @arcgis/core with Next JS Error [ERR_REQUIRE_ESM]
Solved: My intention is to use ArcGis API in a Next JS application. I have used `create next app` to create a simple...
Read more >How to Bypass ES Modules Errors in Next.js with Dynamic ...
In this article, I'll walk you through an error you may get when you are building JavaScript apps with Next.js, and how to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The above PR is not yet available, we will update here when it is rolled
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.