-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Dynamic require of "x" is not supported #2400
Comments
If I manually change the generated |
Also got this issue but with another package. @lovasoa how about renaming title to I updated each package separately in my project to find the cause of the issue and interestingly this is caused by |
That's very strange, from 3.2.0 to 3.21 there shouldn't be a difference related to dynamic requires. |
Also wonder how this happens, but I know nothing of svelte sources so... This is require function before: var __require = (x) => {
if (typeof require !== "undefined")
return require(x);
throw new Error('Dynamic require of "' + x + '" is not supported');
}; and after updating var __require = typeof require !== "undefined" ? require : (x) => {
throw new Error('Dynamic require of "' + x + '" is not supported');
}; Problem could be within immediate condition execution but I'm not sure how. |
I tried to update all the dependencies and just pin |
Manually resetting the old definition of |
This sounds like some bundler (esbuild?) changed the transpilation (the |
I made a PR to esbuild to revert the change. See my comment there. |
I've commented on that PR with more SvelteKit context to help esbuild maintainers understand why we need this. I've also found evanw/esbuild#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 |
Maybe the quick fix here in svelte is to publish a release that uses This is quite an annoying bug, because there is no obvious way to know where it comes from for the end user, who may spend a lot of time looking for a bug in their own code. |
evanw/esbuild#1604 (comment) It sounds like this won't be fixed/supported soon on the esbuild side. We probably should look into a |
Maybe there can even be a temporary fix where the esbuild version is pinned ? This can be done without any implementation work, and would fix all the sveltekit projects that have been broken for two weeks now. |
@lovasoa, very nasty hack, which works for me right now:
console.log('Executing naasty hack, check https://github.com/sveltejs/kit/issues/2400 for updates');
const fs = require('fs');
const { resolve } = require('path');
const buildPath = resolve(__dirname, '../build/index.js');
const data = fs.readFileSync(buildPath, 'utf8');
const newLine = `const require = createRequire(import.meta.url)
`;
fs.writeFileSync(buildPath, `${newLine}${data}`, 'utf8');
{
"scripts": {
"build": "svelte-kit build && node bin/nastyHack.cjs"
}
} |
esbuild just released a new version which contains a require shim which should fix this. |
We were hit by this today. We just updated the package-lock.json of our project ( We deployed on our staging env (our build and deploy uses (strange thing: We were unable to reproduce the problem locally this morning but our staging env was broken) |
Awesome! From Evan's comment the other day, it didn't sound like it was going to be fixed that quickly. I do think it is worth making changes on our end rather than just closing this issue. We should probably try removing our own |
From some brief tests, it looks like we still do need the 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')
}) still doesn't actually do any |
Vite's on |
The latest version of SvelteKit now uses esbuild 0.13.2. It sounds to me like this is probably now fixed as a result, but feel free to correct me if that's wrong and we can reopen |
Yup, all that should have been needed was folks upgrading their transitive esbuild dependency to 0.12.29, which didn't require any action on SvelteKit's part. But we've now updated to 0.13 anyway, so we should be good. |
The same thing after #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 evanw/esbuild#1921 |
If I add import { createRequire } from "module";
const require = createRequire(import.meta.url); before
in // node_modules/.pnpm/[email protected]/node_modules/uglify-js/tools/node.js
var require_node2 = __commonJS({
"node_modules/.pnpm/[email protected]/node_modules/uglify-js/tools/node.js"(exports) {
var fs = __require("fs");
exports.FILES = [
__require.resolve("../lib/utils.js"),
__require.resolve("../lib/ast.js"),
__require.resolve("../lib/transform.js"),
__require.resolve("../lib/parse.js"),
__require.resolve("../lib/scope.js"),
__require.resolve("../lib/compress.js"),
__require.resolve("../lib/output.js"),
__require.resolve("../lib/sourcemap.js"),
__require.resolve("../lib/mozilla-ast.js"),
__require.resolve("../lib/propmangle.js"),
__require.resolve("../lib/minify.js"),
__require.resolve("./exports.js")
];
... |
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@79c310b
lovasoa/sanipasse@79c310b
Logs
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: