-
-
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
esbuild
causes import errors with adapter-node
#6440
Comments
esbuild
causes import errors with adapter-node
This is happening because we now bundle your Your app contains some dependencies that can't be bundled. I was able to get your repro to build and run by moving |
Having the same issue after upgrading to the newest versions of kit and adapter-node. But in my case it says |
How do I find out which dependencies can't be bundled? Just because such errors appear? exports.FILES = [
require.resolve("../lib/utils.js"),
...
]; which for some reason cannot be bundled at the moment. Maybe esbuild needs to add a shim for require.resolve (https://www.npmjs.com/package/@chialab/esbuild-plugin-require-resolve, evanw/esbuild#1311 (comment)). |
@oneserv-heuser |
@AlexRMU Yes, i could but there is nothing spectacular to see, just adds the sveltekit plugin 😀 Solved my issue, I referenced my tailwindconfig in my src code which has led to the bundling of tailwindcss and all its dependencies in the production build. The module |
Without mongoose and html-minifier, the same |
What does this mean? |
Having a similar issue after updating to adapter-node 1.0.0-next.88 |
@Rich-Harris import { createRequire } from "module";
const require = createRequire(import.meta.url); to the build before |
@chintan-infiniteshopping |
I am wrestling with this problem for quite a while now. The code that @AlexRMU mentioned is in a chunk file, in my case 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');
}); If you manually patch this file, and add the following directly above the above mentioned code import { createRequire } from "module";
const require = createRequire(import.meta.url); then this issue seems to be solved (it is on my side). Seems to be difficult to find an elegant solution though. That code is generated by esbuild. I tried to patch the adapter-node to by using esbuilds's I added the banner like explained here: evanw/esbuild#1921 (comment) |
From @spheenik in #6440 (comment)
I can confirm this fixed the issue in my build. I happen to have a chunk with exactly the same name My particular case:
Downgrading to adapter node next.87 for now solves the issue. |
I had a similar issue too.
This worked for me |
👀 Update 1 (2022 September 12): added Undici snippet
I'm facing issues as well running:
👉 TL;DR: SvelteKit's My
👀 Update 1: And the stack trace points to this chunk snippet: // node_modules/undici/lib/client.js
var require_client = __commonJS({
"node_modules/undici/lib/client.js"(exports, module) {
"use strict";
var assert = __require("assert"); I'm still trying to figure this out, but I wonder if the polyfills in packages/kit/src/exports/node/polyfills.js are not being bundled correctly under certain conditions. I attempted to create a repository to reproduce the issue, making use of hooks and I tried adding the linked esbuild setting to my vite.config.js: import { sveltekit } from '@sveltejs/kit/vite'
const config = {
plugins: [sveltekit(),
esbuild: {
bundle: true,
minify: true,
format: 'esm',
target: 'esnext',
platform: 'node',
banner: {
js: 'import { createRequire } from "module";const require = createRequire(import.meta.url);'
},
outExtension: {
'.js': '.mjs'
}
}
}
export default config But then I get a build error (
Setting banner as a string
Manually adding the desired banner string (adding Downgrading to My package.json{
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "vite build",
"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch",
"check": "svelte-check --tsconfig ./jsconfig.json",
"package": "svelte-kit package",
"preview": "vite preview --host",
"start": "vite dev --host"
},
"devDependencies": {
"@sveltejs/adapter-node": "^1.0.0-next.87",
"@sveltejs/kit": "^1.0.0-next.454",
"carbon-components-svelte": "^0.70.1",
"carbon-icons-svelte": "^11.1.0",
"carbon-preprocess-svelte": "^0.9.1",
"svelte": "^3.44.0",
"svelte-progress-bar": "^3.0.2"
},
"type": "module",
"dependencies": {
"mysql2": "^2.3.3",
"slug": "^8.0.0"
}
}
What vite/esbuild config worked for you? |
In my case, we're still on sveltekit next.471 and adapter node next.87, i.e. before the introduction of esbuild for including dependencies. |
@dlebech thanks for the suggestion; I went with the workaround you suggested and downgraded to node-adapter 87. Since my project is built as a docker image, I'll have to include all dependencies instead of the leaner production serve I can tell that node-adapter is marking its dependencies as external: kit/packages/adapter-node/index.js Lines 48 to 60 in 70e3c34
Perhaps it needs to be bundled in, or all dependencies' dependencies should be recurisvely bundled; I'm not too sure. |
got this error resolved by using $env/static/private instead of dotenv for environment variables. |
@oneserv-heuser can you elaborate on how you solved the issue with tailwind? I'm not sure if I understand your solution correctly. I'm also running into the |
I updated my post above (#6440 (comment)), noting a Here's a work in progress reproduction: https://github.com/theetrain/sveltekit-issue-6440 |
This comment was marked as outdated.
This comment was marked as outdated.
Edit: I figured out why external dependencies were not being respected in the esbuild. I was importing firebase as @Rich-Harris it's not enough to move dependencies from Here's a reproduction of the issue with a single dependency The manual workaround mentioned above solves the issue in this repo as well, but is not feasible to include in automated pipelines. The |
I got the issue when using I solved the issue with moving the tailwindconfig back to where it belongs, to the root directory of my project. I then wrote a little rollup plugin which takes the config file, extracts all the parameters I use in my production code and then writes it into a new file residing in import tailwindConfig from '../tailwind.config.js'
import * as fs from 'fs'
import { pick } from 'lodash-es'
/* All keys which are needed in the application from the tailwind configuration. */
const requiredKeys = ['screens', 'colors', 'extend', 'spacing']
/**
* This takes the tailwind config file, prepares it and writes it to src/lib so values from the configuration can be
* used in components.
*/
export default function bundleTailwindConfig () {
return {
name: 'tailwind-config-bundler',
buildStart () {
let configObject = tailwindConfig.theme
configObject = pick(configObject, requiredKeys)
const content = `/* this file is generated — do not edit it! */ export default ${JSON.stringify(configObject)}`
fs.writeFile('./src/lib/tailwind.config.js', content, 'utf8', (error) => {
if (error) throw error
console.log('Tailwind config file successfully processed.')
})
}
}
} Hope this explanation is sufficient. But I cant help you with the issue that you get the same error as me without importing anything from tailwind :/ |
So, #6896 appeared and I think the problem with When I try to build all the dependencies, it appears:
It was solved by changing the max-old-space-size, but this is not always possible. |
Same here; after upgrading to I can now run a built application after installing production modules only via |
adapter-node now uses |
@bluwy btw i am also seeing this in adapter-auto on Netlify as well i am not sure how to fix. |
agree. i'll just pin my version for adapter-netlify right now, but this continuing to be a bug/problem for netlify as far as i'm aware. cc @brittneypostma fyi |
issue dates back to adapter auto v74 as far as i can tell swyxio/swyxkit#117; last working version is v72 |
…Dynamic require of "' + x + '" is not supported');` > Dependency location error, move all devDependencies to dependencies(sveltejs/kit#6440 (comment))
I am still seeing this issue today, preventing any upgrade of sveltekit adapter netlify version (current version 84) #7839 |
|
We are currently also rolling out a fix that should fix the issue in the bundling on Netlify when using |
ah wonderful, thank you! |
Describe the bug
Same issue as #2400
After #6372, I get:
Perhaps the problem is evanw/esbuild#1921
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-sczcqj?file=README.md
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: