Error: Dynamic require of "crypto" is not supported
See original GitHub issueDescribe the bug
I’m getting this error on my Cloudflare Pages site but can’t reproduce locally. I am feeding in ‘esnext’ to the adapter because I have to for anything to compile. Might be part of the problem, idk, but if that’s the cause then I have another question: why am I not supposed to use ECMA from the last 2 years? 😉
from my svelte config:
adapter: adapter({
target: "esnext",
minify: false,
logLevel: "error",
})
I believe it’s caused by this line: https://github.com/sveltejs/kit/blob/827d1623d64a9886032c8bfc8e2315420d1599d0/packages/kit/src/runtime/server/page/csp.js#L24
Reproduction
I am not trying to be a dick, I am very busy and don’t have the time right now to reproduce. I’ve explained all steps necessary to reproduce; it’s an extremely simple setup. Just want to report this bug. Sorry if that isn’t allowed; I know you’re all busy too.
Logs
No response
System Info
Cloudflare Workers node version 17.5.0
Severity
blocking all usage of SvelteKit
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
@bhvngt please create new issues rather than piggybacking on existing ones, unless it’s exactly the same issue. Things are liable to get lost in the mix otherwise. I’ve opened #4915 which works around the issue you found by preventing esbuild trying to bundle Node’s built-in
crypto
module.@CoolOppo unfortunately since I can’t reproduce this I have to close this issue. It’s not at all clear why it would be happening (
crypto
should be available in the worker environment, so SvelteKit shouldn’t be trying to dynamically import Node’scrypto
module), so there’s no realistic chance of fixing it without a reproduction. Feel free to open a new issue if you’re able to create a repro.Hi, I am facing similar issue with a slightly different setup.
minify
to false, my build is successful but my resources don’t get minified.minify
toesbuild
I get.svelte-kit/output/server/index.js:6:9958: ERROR: Could not resolve "crypto"
due to https://github.com/sveltejs/kit/blob/827d1623d64a9886032c8bfc8e2315420d1599d0/packages/kit/src/runtime/server/page/csp.js#L25.svelte.config.js
esbuild-plugin-node-polyfills is not an option as it requires me to install multiple peer dependencies and it requires an outdated version of esbuild.
Is there any other work around possible? I can still run the build using
svelte-kit preview
but my CI breaks since my build return error.