Closed ehsanrezaeee closed 3 months ago
i use jsonwebtoken package in the middleware. i think the turbopack cant work with modules belong to node js environment exclusively
if anyone wants a workaround, you can use "jose" instead of "jsonwebtoken" npm package
Hello, I'm using crypto directly
import crypto from 'crypto';
export const crypt = (password: string): string =>
crypto.createHash('md5').update(crypto.createHash('sha1').update(password).digest('hex')).digest('hex');
Inside the authorized
callback in next-auth, and I have the same issue with--turbo
Error: Cannot find module 'crypto'
at <unknown> (./src/lib/crypt.ts:0:0)
at <unknown> (./src/lib/crypt.ts:0:0)
at [project]/src/lib/crypt.ts [middleware] (ecmascript) (./file:///Users/fabriziotognetto/.../.next/server/edge/chunks/ssr/src_7cd4a5._.js:18:3)
at <unknown> (./[turbopack]/dev/runtime/base/runtime-base.ts:347:21)
at runModuleExecutionHooks (./[turbopack]/dev/runtime/base/runtime-base.ts:403:5)
at instantiateModule (./[turbopack]/dev/runtime/base/runtime-base.ts:345:5)
at getOrInstantiateModuleFromParent (./[turbopack]/dev/runtime/base/runtime-base.ts:451:10)
at esmImport (./[turbopack]/shared/runtime-utils.ts:215:18)
at <unknown> (./src/app/(auth)/auth.ts:0:0)
at [project]/src/app/(auth)/auth.ts [middleware] (ecmascript) (./file:///Users/fabriziotognetto/.../.next/server/edge/chunks/ssr/src_7cd4a5._.js:147:3) {
digest: undefined
}
1 | import crypto from 'crypto';
2 | export const crypt = (password: string): string =>
3 | crypto.createHash('md5').update(crypto.createHash('sha1').update(password).digest('hex')).digest('hex');
Thanks for the report with a great reproduction! I've opened a fix here: #65171.
Verified the reproduction correctly compiles on next@canary
(which holds the fix in #65171) 🎉
Verified the reproduction correctly compiles on
next@canary
(which holds the fix in #65171) 🎉
now works properly. thanks
Thanks for confirming!
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Link to the code that reproduces this issue
https://github.com/ehsanrezaeee/test-jwt
To Reproduce
Current vs. Expected behavior
i expected to redirected to a page in my app with middleware logic. however i encounter the following error:
Which area(s) are affected? (Select all that apply)
App Router, Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Other (Deployed)
Additional context
i tested my app with nextjs v14.2.1 latest version
PACK-2954