Vite error in make-crypter.js - Vite seems to think "crypto" is a local module
See original GitHub issueJust updated svelte-kit-cookie-session from 1.2.4 to 1.3.0, and now I’m getting the following Vite error whenever I run pnpm run dev
:
1:10:31 PM [vite] new dependencies found: svelte-kit-cookie-session, updating...
> node_modules/svelte-kit-cookie-session/dist/utils/crypto/make-crypter.js:9:75: error: Could not read from file: (REPOROOT)/crypto
9 │ import { pbkdf2Sync, createDecipheriv, createCipheriv, randomBytes, } from "crypto";
╵ ~~~~~~~~
(I replaced my repo root with the text (REPOROOT)
above since I’m running this from a directory nested about five deep in my folder hierarchy, and without that replacement the error message was even more annoyingly long than it already is.)
Running with npm
instead of pnpm
I get the same error. However, if I run pnpm run build
followed by pnpm run preview
then everything works.
I know I need to somehow tell Vite that svelte-kit-cookie-session
is only Node-based and should therefore be allowed to import Node packages like crypto
, but I’m not yet familiar enough with Svelte-Kit to know how to do that off the top of my head. Which leads me to report it here, because you might want to add something to the svelte-kit-cookie-session README about how to work around this Vite behavior. (And I’ll update this issue if I figure it out.)
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (7 by maintainers)
I have updated the README and going to close this issue now. I’m on
UTC+1
Great; I’ll close the issue once the README is updated, or you can close it if I don’t get to it. (I’m in a far eastern timezone, UTC+lots, so I go to sleep while most of America is just waking up).