next.js: Module not found: Can't resolve 'crypto'
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
❯ npx --no-install next info
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
Binaries:
Node: 19.1.0
npm: 8.19.3
Yarn: 3.3.0
pnpm: 7.24.3
Relevant packages:
next: 13.4.5-canary.0
eslint-config-next: 13.4.2
react: 18.2.0
react-dom: 18.2.0
typescript: 5.0.4
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
To Reproduce
/demo/page.tsx
:
import { authOptions } from '@/lib/next-auth';
import { getServerSession } from 'next-auth/next';
export default async function Page() {
const session = await getServerSession(authOptions);
return (
<>
<pre>{JSON.stringify(session)}</pre>
</>
);
}
export const dynamic = 'force-dynamic';
Describe the Bug
works on 13.3.1
but when i tried 13.3.4-13.4.4 or canary
13.3.2,13.3.3 when started, cannot open localhost:3000 always loading.
Expected Behavior
Which browser are you using? (if relevant)
Brave 113
How are you deploying your application? (if relevant)
Vercel
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 23 (3 by maintainers)
(please refrain from mass tagging maintainers in the future)
This is correct,
crypto
does not need to be imported.The current version of
next-auth
is not edge compatible yet anyway, but the upcoming version will be.So this error is currently expected.
I’m having the same issue. I tried using the latest 13.4.5-canary.3 and the error is still there.
It can be reproduced by just creating a simple route:
It works by removing the runtime export.
Also, I’m not sure if there is anything to do with it, but i’m using nvm.
I added the following in package.json and it was fixed:
nodejs: v19.1.0
Clone this repo: https://github.com/wshow/crypto-bug-mvp
set ENV:
github oauth app redirect set
http://localhost:3000/api/auth/callback/github
then login.
https://github.com/willin/domain/commit/f8699c9cc98fdc05bde58f624f20df437b94cb12#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
I’ve already downgrade next.js version and move on development…