Giter Site home page Giter Site logo

Comments (8)

Dragate avatar Dragate commented on September 13, 2024 1

Had the same issue. Had to swap to bcryptjs that is compatible with the edge runtime.

from next.js.

Jayllyz avatar Jayllyz commented on September 13, 2024 1

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.

areeburrub avatar areeburrub commented on September 13, 2024

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.

areeburrub avatar areeburrub commented on September 13, 2024

I think I got the answer:
https://nextjs.org/learn/dashboard-app/adding-authentication#password-hashing

from next.js.

chriskuech avatar chriskuech commented on September 13, 2024

@areeburrub my repro shows the middleware only indirectly importing bcrypt as that article recommends

from next.js.

chriskuech avatar chriskuech commented on September 13, 2024

@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.

areeburrub avatar areeburrub commented on September 13, 2024

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.

chriskuech avatar chriskuech commented on September 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.