assert is not a function error, when import csrf in middleware.js
Answered
andresdotsh posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/843612556995854427/a27165e60cf82474c50b594109142091.webp?size=256)
andresdotshOP
Hi everyone π,
I'm having the following problem and I was wondering if you could help or give me an idea of what's going on.
You can try this on a fresh Next.js installation. [code example repo](https://github.com/andresdotsh/csrf-next-issue/tree/main) π
When I import the
This is because the [csrf](https://www.npmjs.com/package/csrf) library depends on the [rndm](https://www.npmjs.com/package/rndm) library, which uses NodeJS's
This error only occurs if I import it in the middleware.js file, it doesn't happen in page.js for example.
Does anyone have any idea why this might be happening? I would like to use this
More info:
-
-
-
-
- I'm using nextjs
Pictures:
![Error example](https://i.ibb.co/dgZF8kf/err1.png)
![Error example 2](https://i.ibb.co/JqXPsNN/err2.png)
I'm having the following problem and I was wondering if you could help or give me an idea of what's going on.
You can try this on a fresh Next.js installation. [code example repo](https://github.com/andresdotsh/csrf-next-issue/tree/main) π
When I import the
csrf
library in the middleware.js
file, I get an error that says assert is not a function
.This is because the [csrf](https://www.npmjs.com/package/csrf) library depends on the [rndm](https://www.npmjs.com/package/rndm) library, which uses NodeJS's
assert
in its code.This error only occurs if I import it in the middleware.js file, it doesn't happen in page.js for example.
Does anyone have any idea why this might be happening? I would like to use this
csrf
library, but this error is preventing me from doing so. Thanks in advance for any help π.More info:
-
nodejs v20.15.1
-
next@14.2.5
-
csrf@3.1.0
-
yarn@1.22.22
- I'm using nextjs
app router
Pictures:
![Error example](https://i.ibb.co/dgZF8kf/err1.png)
![Error example 2](https://i.ibb.co/JqXPsNN/err2.png)
Answered by andresdotsh
Someone already gave me the [answer here](https://github.com/vercel/next.js/discussions/68168). βοΈβ€οΈ
1 Reply
![Avatar](https://cdn.discordapp.com/avatars/843612556995854427/a27165e60cf82474c50b594109142091.webp?size=256)
andresdotshOP
Someone already gave me the [answer here](https://github.com/vercel/next.js/discussions/68168). βοΈβ€οΈ
Answer