Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AleksaSimovic1 opened this issue Jun 17, 2024 · 7 comments
Open

Comments

@AleksaSimovic1
Copy link

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

@AleksaSimovic1 AleksaSimovic1 changed the title Module parse failed: Unexpected character '�' @node-rs/argon2: Module parse failed: Unexpected character '�' Jun 17, 2024
@Sheharyar566
Copy link

Sheharyar566 commented Jun 26, 2024

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

@dBianchii
Copy link

Also having this. I added

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

But it didn't work

@Sheharyar566
Copy link

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 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@dBianchii @Sheharyar566 @AleksaSimovic1 and others