node-rs icon indicating copy to clipboard operation
node-rs copied to clipboard

@node-rs/argon2: Module parse failed: Unexpected character '�'

Open simovicaleksa opened this issue 1 year ago • 7 comments

The Problem

After installing this package using pnpm add @node-rs/argon2 my dev server crashes immediately with the following error:

Module parse failed: Unexpected character '�' (1:2)
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
(Source code omitted for this binary file)

Import trace for requested module:
./node_modules/.pnpm/@[email protected]/node_modules/@node-rs/argon2-win32-x64-msvc/argon2.win32-x64-msvc.node
./node_modules/.pnpm/@[email protected]/node_modules/@node-rs/argon2/index.js
./src/lib/auth/index.ts
./src/actions/login.ts

The character in question is: "U+FFFD".

I am using a Next.js 14 with server actions, where I use @node-rs/argon2 for hashing and verifying passwords on the server.

There is only two functions where I use @node-rs/argon2:

import { hash, verify } from "@node-rs/argon2"

export async function hashPassword(password: string) {
  const hashedPassword = await hash(password, {
    memoryCost: 19456,
    parallelism: 1,
    timeCost: 2,
  })
  return hashedPassword
}

export async function verifyPassword(password: string, hashedPassword: string) {
  const isValid = await verify(hashedPassword, password)
  return isValid
}

Node Version

This might be the problem since it is not listed in the support matrix.

v20.12.0

Operating System

Windows 10 x64

simovicaleksa avatar Jun 17 '24 09:06 simovicaleksa

Temporary fix: Try adding this block to next.config file:

	experimental: {
		serverComponentsExternalPackages: ["@node-rs/argon2"]
	}

For some reason, it seems like this package doesn't work with Turbopack. Source: https://lucia-auth.com/tutorials/username-and-password/nextjs-app

Sheharyar566 avatar Jun 26 '24 08:06 Sheharyar566

Also having this. I added

experimental: {
		serverComponentsExternalPackages: ["@node-rs/argon2"]
	}

But it didn't work

dBianchii avatar Jul 03 '24 15:07 dBianchii

Temporary fix: Try adding this block to next.config file:

	experimental: {
		serverComponentsExternalPackages: ["@node-rs/argon2"]
	}

For some reason, it seems like this package doesn't work with Turbopack. Source: https://lucia-auth.com/tutorials/username-and-password/nextjs-app

This fixed my issue but is it recommended on production?

Well, it does say "experimental" 😁 so may be not 🤷‍♂️

Sheharyar566 avatar Aug 23 '24 14:08 Sheharyar566