Comments (8)
Had the same issue. Had to swap to bcryptjs
that is compatible with the edge runtime.
from next.js.
I'm using NodeJS runtime so it seems like that does not apply.
Middleware in Next.js are using edge runtime.
https://nextjs.org/docs/app/building-your-application/routing/middleware#runtime
A good alternative to bcrypt which works for multiple runtime : jose
from next.js.
Yes I am also having similar error.
Not only using bcrypt in middleware is producing error but also if it's being imported in a file and I use a exported server action from that file then also I am having the same error.
I am using a server action and the file which have all the action imports bcrypt for some other server action and still I am having error.
PS: I also want to usie bcrypt function in the middleware but I am just describing the fact that only imports are also throwing error.
> next dev
▲ Next.js 14.2.5
- Local: http://localhost:3000
- Environments: .env.local, .env
✓ Starting...
✓ Ready in 24.1s
○ Compiling /src/middleware ...
⨯ ./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>
Import trace for requested module:
./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/.pnpm/[email protected]/node_modules/bcrypt/bcrypt.js
./src/utils/auth.ts
./src/_actions/auth.ts
⚠ ./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js
Module not found: Can't resolve 'node-gyp' in 'E:\Projects\Spaceship CMS\spaceship-cms\node_modules\.pnpm\@[email protected]\node_modules\@mapbox\node-pre-gyp\lib\util'
from next.js.
I think I got the answer:
https://nextjs.org/learn/dashboard-app/adding-authentication#password-hashing
from next.js.
@areeburrub my repro shows the middleware only indirectly importing bcrypt as that article recommends
from next.js.
@Dragate bcryptjs
hasn't been updated in 8 years and appears to be abandonware, which is concerning for a security library, and bcrypt
is recommended in @areeburrub 's link, so I think it's important that bcrypt
works in nextjs.
from next.js.
There's nothing we can really do.
The problem is with the edge runtime as it doesn't support some NodeJs features even though it's a NodeJs runtime.
Theres always an alternate way to do things on the edge and if there is nothing to do then people create proxy api for the function to use in the edge.
I just moved the functions using bcrypt to another file and it works for me, as I wasn't using bcrypt in the middleware.
from next.js.
@areeburrub I understand the limitations of the edge runtime; however, I'm using NodeJS runtime so it seems like that does not apply.
I'm not sure what you mean by this, as this sounds like it matches my linked repro:
I just moved the functions using bcrypt to another file and it works for me, as I wasn't using bcrypt in the middleware.
from next.js.
Related Issues (20)
- AsyncLocalStorage accessed in runtime where it is not available HOT 1
- generateStaticParams validation makes react-router migrations difficult
- An error occurred in `next/font`. TypeError: Cannot read properties of undefined (reading 'ascent') HOT 1
- Scroll Position Issue When Changing Pages
- Compilation is slow HOT 1
- Server actions regression in 14.2.8: “Failed to find Server Action” HOT 13
- Not deployable out the gate
- Intercepting Routes - refresh when modal is open cannot go back to modal again unless another refresh HOT 1
- app router does not resolve routes according to `generateStaticParams` constraints HOT 9
- Invalid Metadata properties caused by Route Group and Parallel Route at the same Level HOT 1
- Setting a cookie in middleware & a server action results in duplicate Set-Cookie headers HOT 8
- NoFallbackError on 404 routes with pages router and middleware. HOT 1
- NoFallbackError on 404 routes with pages router and middleware. HOT 1
- Docs: The docs say Next.JS 14 supports experimental PPR but anecdotal evidence says otherwise HOT 1
- Debugging issue with Error Code SIGLL HOT 1
- Version info in error page shows different font sizes
- Debugging issue with Error Code SIGLL
- @next/swc-android-arm64 on build error HOT 1
- Server action in 18.2.6 vs 18.2.8 is not longer able to import server action in client component HOT 6
- With the `experimental-https` and `-H` options, the next dev will show a different URL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.