question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Dynamic require of "crypto" is not supported

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Rich-Harriscommented, May 14, 2022

@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’s crypto 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.

0reactions
bhvngtcommented, May 10, 2022

Hi, I am facing similar issue with a slightly different setup.

svelte.config.js

	kit: {
		adapter: adapterCloudflare(),
	        build: {
				target: "esnext",
				minify: "esbuild",

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Can't resolve 'crypto' - Stack Overflow
I ran into a similar issue lately while trying to use another library (tiff.js) in a small project I was experimenting with.
Read more >
Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The error [ERR_REQUIRE_ESM]: require() of ES Module not supported. Instead change the require of index.js to a dynamic import() which is available in...
Read more >
Command-line API | Node.js v19.3.0 Documentation
Enable FIPS-compliant crypto at startup. (Requires Node.js to be built against FIPS-compatible OpenSSL.) --enable-source-maps #.
Read more >
JavaScript runtime features for CloudFront Functions
The const and let statements are not supported. ... You can load the module using require('crypto') . ... The following error objects are...
Read more >
Intro to Pulumi: Dynamic Resource Providers
Because they are not shareable, dynamic resource providers do not need a plugin. ... supports all CRUD operations, but only the create function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found