Error: Dynamic require of "x" is not supported

See original GitHub issue

Describe the bug

Upgrading to the latest version of sveltekit broke adapter-node for my application. Now the application works in development, but when packaged by adapter-node, it throws `` on start

Reproduction

It can be reproduced on lovasoa/sanipasse@79c310b88345773249ff0c1a9ff00594b712ee83

https://github.com/lovasoa/sanipasse/commit/79c310b88345773249ff0c1a9ff00594b712ee83

Logs

file:///home/olojkine/dev/sanipasse/build/middlewares.js:26
  throw new Error('Dynamic require of "' + x + '" is not supported');
        ^

Error: Dynamic require of "crypto" is not supported
    at __require (file:///home/olojkine/dev/sanipasse/build/middlewares.js:26:9)
    at node_modules/@peculiar/webcrypto/build/webcrypto.js (file:///home/olojkine/dev/sanipasse/build/middlewares.js:8119:19)
    at __require2 (file:///home/olojkine/dev/sanipasse/build/middlewares.js:32:44)
    at node_modules/isomorphic-webcrypto/src/index.js (file:///home/olojkine/dev/sanipasse/build/middlewares.js:10253:22)
    at __require2 (file:///home/olojkine/dev/sanipasse/build/middlewares.js:32:44)
    at node_modules/isomorphic-webcrypto/src/main.js (file:///home/olojkine/dev/sanipasse/build/middlewares.js:10262:22)
    at __require2 (file:///home/olojkine/dev/sanipasse/build/middlewares.js:32:44)
    at file:///home/olojkine/dev/sanipasse/build/middlewares.js:10271:46
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)

System Info

System:
    OS: Linux 5.13 Fedora 34 (Workstation Edition) 34 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 2.64 GB / 15.28 GB
    Container: Yes
    Shell: 5.1.0 - /bin/bash
  Binaries:
    Node: 16.5.0 - /usr/bin/node
    Yarn: 1.22.10 - /usr/bin/yarn
    npm: 7.19.1 - /usr/bin/npm
  Browsers:
    Firefox: 91.0.2
  npmPackages:
    @sveltejs/adapter-node: next => 1.0.0-next.46 
    @sveltejs/adapter-static: next => 1.0.0-next.18 
    @sveltejs/kit: next => 1.0.0-next.165 
    svelte: ^3.38.3 => 3.42.5 

Severity

blocking all usage of SvelteKit

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
Conduitrycommented, Sep 14, 2021

I’ve commented on that PR with more SvelteKit context to help esbuild maintainers understand why we need this.

I’ve also found https://github.com/evanw/esbuild/issues/946 which appears to be the main issue for why we needed this shim in the first place. I haven’t checked whether the other suggested workarounds in that issue (like the banner one, for example) will still help us here even with the change to __require.

3reactions
AlexRMUcommented, Aug 30, 2022

The same thing after https://github.com/sveltejs/kit/pull/6372

var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
    get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function (x) {
    if (typeof require !== "undefined")
        return require.apply(this, arguments);
    throw new Error('Dynamic require of "' + x + '" is not supported');
});

...

var crypto_1 = __importDefault(__require("crypto"));

Perhaps the problem is https://github.com/evanw/esbuild/issues/1921

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "Dynamic require of "os" is not supported" #1921
Just run node index.mjs. This was generated from running build which executes esbuild to bundle this file. Problem: The problem is that node ......
Read more >
When using esbuild with external react I get Dynamic require ...
On top of that, I assume, esbuild adds some check whether the require is supported in the target environment, which in the browser...
Read more >
dynamic require of "path" is not supported - You.com - You.com
This error is appearing not matter what I do. I tried dynamic import as suggested by the error message but it didn't work....
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 >
API - esbuild
Source root; Sourcefile; Sources content; Supported; Tree shaking; Tsconfig raw. #Build API. The build API call operates on one or more files ...
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