SyntaxError: Cannot use import statement outside a module
See original GitHub issueAdapter type
Environment
System:
OS: macOS 12.3
CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
Memory: 61.76 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.1 - ~/Library/pnpm/node
npm: 8.5.0 - ~/Library/pnpm/npm
Browsers:
Safari: 15.4
npmPackages:
next: ^12.0.11-canary.4 => 12.1.0
next-auth: latest => 4.3.0
react: ^17.0.2 => 17.0.2
npmPackages:
@next-auth/mongodb-adapter: 1.0.2 => 1.0.2
Reproduction URL
https://github.com/claudiorivera/next-auth-example
Describe the issue
If pnpm
is not supported, feel free to ignore this!
I’ve been migrating my projects from yarn
to pnpm
and most of my them have worked without a hitch, but I’m getting an error from the mongodb-adapter
when trying to develop my game-night
repo locally.
I reproduced with the next-auth-example for this issue.
Here’s the call stack:
Call Stack
<unknown>
/Users/claudio/Developer/next-auth-example/node_modules/.pnpm/ (next-auth+mongodb-adapter@1.0.2_mongodb@4.4.1+next-auth@4.3.0/node_modules/@next-auth/mongodb-adapter/dist/index.js (2)
Object.compileFunction
node:vm (352:18)
wrapSafe
node:internal/modules/cjs/loader (1032:15)
Module._compile
node:internal/modules/cjs/loader (1067:27)
Object.Module._extensions..js
node:internal/modules/cjs/loader (1157:10)
Module.load
node:internal/modules/cjs/loader (981:32)
Function.Module._load
node:internal/modules/cjs/loader (822:12)
Module.require
node:internal/modules/cjs/loader (1005:19)
require
node:internal/modules/cjs/helpers (102:18)
Object.@next-auth/mongodb-adapter
file:///Users/claudio/Developer/next-auth-example/.next/server/pages/api/auth/[...nextauth].js (22:18)
__webpack_require__
file:///Users/claudio/Developer/next-auth-example/.next/server/webpack-api-runtime.js (33:42)
How to reproduce
- On a fresh install of macOS
- Installed
pnpm
- Installed Node with
pnpm env use --global lts
- Cloned the next-auth-example
- Followed the instructions from the docs (substituting the
npm
/yarn
commands for theirpnpm
equivalent) - Ran
pnpm dev
- In the app, click on
Sign In
- Unhandled server error appears
Expected behavior
I expect to get the next-auth-example
’s sign-in page instead of an unhandled server error.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
"Uncaught SyntaxError: Cannot use import statement outside ...
This means that you're using the native source code in an unaltered/unbundled state, leading to the following error: Uncaught SyntaxError: ...
Read more >How to fix "cannot use import statement outside a module"
I stumbled on this error: Uncaught SyntaxError: cannot use import statement outside a module while importing a function from a JavaScript file.
Read more >Cannot use import statement outside a module [React ...
When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.
Read more >Cannot use import statement outside module in JavaScript
The "SyntaxError: Cannot use import statement outside a module" occurs when we use the ES6 Modules syntax in a script that was not...
Read more >How to solve: cannot use import statement outside a module
When you see the error message Uncaught SyntaxError: cannot use import statement outside a module, it means you're using an import statement ......
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 Free
Top 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
Duplicate of #4198. Currently trying to do a new release. 👍
I can confirm that downgrading @next-auth/mongodb-adapter to version 1.0.1 “fixes” the issue for the moment.