kit: devalue cause crash on Netlify after update
Describe the bug
I updated some sveltekit-related npm packages then build
successfully on local/dev but when deployed it just crashed on Netlify
Error - No "exports" main defined in /var/task/node_modules/devalue/package.json
Reproduction
package.json
{
"name": "portfolio",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch",
"test": "playwright test",
"lint": "prettier --check . && eslint .",
"format": "prettier --write .",
"ngrok": "ngrok http 4173"
},
"devDependencies": {
"@iconify-json/ph": "^1.1.2",
"@playwright/test": "^1.25.0",
"@supabase/supabase-js": "^1.35.6",
"@sveltejs/adapter-auto": "next",
"@sveltejs/adapter-netlify": "^1.0.0-next.75",
"@sveltejs/kit": "next",
"atropos": "^1.0.2",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^4.0.0",
"normalize.css": "^8.0.1",
"nprogress": "^0.2.0",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",
"svelte": "^3.49.0",
"svelte-check": "^2.8.0",
"typescript": "^4.7.2",
"unplugin-icons": "^0.14.8",
"vite": "^3.1.0-beta.1",
"vite-imagetools": "^4.0.5"
},
"type": "module"
}
Logs
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /var/task/node_modules/devalue/package.json
at new NodeError (node:internal/errors:372:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
at packageExportsResolve (node:internal/modules/esm/resolve:693:7)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/var/task/.netlify/server/index.js:49:22)
System Info
Binaries:
Node: 17.9.0 - D:\nodejs\node.EXE
npm: 8.5.3 - D:\nodejs\npm.CMD
Browsers:
Chrome: 104.0.5112.102
Edge: Spartan (44.19041.1023.0), Chromium (104.0.1293.70)
Internet Explorer: 11.0.19041.1202
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.70
@sveltejs/adapter-netlify: ^1.0.0-next.75 => 1.0.0-next.75
@sveltejs/kit: next => 1.0.0-next.456
svelte: ^3.49.0 => 3.49.0
vite: ^3.1.0-beta.1 => 3.1.0-beta.1
Severity
blocking all usage of SvelteKit
Additional Information
I did look at some reports on discord and changed my vite version to “vite”: “^3.1.0-beta.1”,
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 21
- Comments: 37 (10 by maintainers)
Links to this issue
Commits related to this issue
- temporary workaround for https://github.com/sveltejs/kit/issues/6462 — committed to peterwilmshurst/svelte-netlify by peterwilmshurst 2 years ago
- Tweak Netlify adapter to circumvent crash: https://github.com/sveltejs/kit/issues/6462 — committed to dkmooers/reforestation-simulator by dkmooers 2 years ago
- adapter: netlify({ edge: true }) // temporarily fix https://github.com/sveltejs/kit/issues/6462 — committed to elron/svelte-interactive-carousel by elron 2 years ago
- switch to adapter-netlify for time being and use edge until https://github.com/sveltejs/kit/issues/6462 resolves static > Using @sveltejs/adapter-static fails with error @sveltejs/adapter-static: ... — committed to janosh/svelte-multiselect by janosh 2 years ago
- Better on mobile and better about which option is active (#103) * update deps * set vite dev and preview ports to 3000 * sveltekit '$app/env' renamed to '$app/environment' * determine active... — committed to janosh/svelte-multiselect by janosh 2 years ago
- netlify configs see https://github.com/sveltejs/kit/issues/6462 — committed to antievictionmappingproject/www by 18kimn 2 years ago
- Temporary workaround for https://github.com/sveltejs/kit/issues/6462 — committed to marccoup/blog by marccoup 2 years ago
- fix: work around sveltekit#6462 https://github.com/sveltejs/kit/issues/6462 — committed to arkutils/arkutils-website by coldino 2 years ago
- Fix the devalue issue https://github.com/sveltejs/kit/issues/6462 — committed to gaia-charge/website by suda 2 years ago
- fix netlify svelte-kit bug, by manually adding devalue dep - https://github.com/sveltejs/kit/issues/6462#issuecomment-1237092740 — committed to 0xnook/token-delegation-interface by 0xnook 2 years ago
- Fix netlify missing ESM support https://github.com/sveltejs/kit/issues/6462 — committed to valeriegc/triviagame by valeriegc 2 years ago
- Fix netlify missing ESM support https://github.com/sveltejs/kit/issues/6462 — committed to valeriegc/triviagame by valeriegc 2 years ago
- Fixing a problem with Netlify and SvelteKit https://github.com/sveltejs/kit/issues/6462 — committed to efedorenko/accessiblepalette by efedorenko 2 years ago
- Added Header and workaround for https://github.com/sveltejs/kit/issues/6462 — committed to SaschaDoe/RandomTableApp by SaschaDoe 2 years ago
- fix function crash according to https://github.com/sveltejs/kit/issues/6462 — committed to rhersen/timpris by deleted user 2 years ago
- Install devalue According to <https://github.com/sveltejs/kit/issues/6462#issuecomment-1244680791> — committed to EthanThatOneKid/acmcsuf.com by EthanThatOneKid 2 years ago
- Fix the devalue issue https://github.com/sveltejs/kit/issues/6462 — committed to gaia-charge/website by suda 2 years ago
This issue is happening because the new version of
devalue
is ESM-only, and Netlify is trying torequire
it. The maintainers are working on a more permanent solution, but in the meantime you can temporarily work around the issue one of the following ways:netlify.toml
at the root of the project:svelte.config.js
:This appears to have been fixed with #6666 – my Netlify sites now work as expected on the latest adapter version. @wentallout (and others in this thread) can you remove any workarounds in
netlify.toml
orsvelte.config.js
and update to the latest Netlify adapter to see if that fixes your issue?I’m sorry for the pain this is causing people. I can confirm that Netlify is prioritising a fix for this, to allow ESM entrypoints. In the meantime, would an approach similar to the one used by Nuxt do the job? They have a CJS entrypoint that dynamically imports the ESM bundle.
I think I’m back in business on Netlify.
devalue@3.1.3
which adds themain
field inpackage.json
and I made sure that mypackage-lock.json
specifies the3.1.3
version (link to commit in devalue repo)'devalue'
to thessr.noExternal
array in the Vite configAfter doing both steps it works. My
ssr.noExternal
array already contained other ESM packages before that (due to lack of ESM support on Netlify)Hi I am doing like this, refering to this https://github.com/Rich-Harris/devalue/issues/36
package-lock.json
(because still contains devalue 3.1.2)pnpm-lock.yaml
(because still contains devalue 3.1.2)pnpm install
(will create fresh pnpm-lock.yaml)vite.config.js
to this+1, after a @sveltejs/kit upgrade from
1.0.0-next.445
1.0.0-next.449
production builds on Netlify crash on load withEdit: Seems to be caused by #6318 bumping devalue’s version to 3.1.2
The issue described in the OP is happening because Netlify doesn’t support ESM (https://github.com/netlify/zip-it-and-ship-it/issues/750), and recent versions of SvelteKit depend on
devalue@3
which is an ESM package.Ultimately, this will continue to affect any app deployed to Netlify that has an ESM dependency — we’ve just been lucky not to stumble onto one until now. As more of the ecosystem goes ESM-only, this will happen more frequently.
The reason this doesn’t happen if you specify
node_bundler=esbuild
is that unlike the defaultzisi
(zip-it-and-ship-it),esbuild
bundles everything to a single file rather than just zipping up stuff innode_modules
. But that’s too blunt a remedy —esbuild
can’t bundle everything (i.e. native dependencies).I think the solution is to adopt the same strategy
adapter-node
has — useesbuild
within the adapter to bundle everything indevDependencies
, but leave prod dependencies unbundled. If you’re usingzisi
then native dependencies will continue to work, and if you’re usingesbuild
then it will just get bundled a second time, harmlessly.@xpat looks like you have some out-of-date dependencies somewhere — if something is doing this…
…it means it’s expecting
devalue@2
, notdevalue@3
(which uses a named export).@rowantrollope seems like you have the opposite problem — that code expects
devalue@3
, but you might havedevalue@2
installed somehow?Just to visualize the error 😃
@brittneypostma I just
pnpm add -D devalue
to solve the problem. But would be interesting to find out whydevalue
wasn’t installed automatically.Putting “devalue”: “^3.1.3” in my dependencies section of package.json fixed it.
I’m also having the same problem. But when I change vite.config.js to like this
everything is working normally and everything seems to be working
@demetrius-mp Doesn’t look related. It says
@mapbox
in the error. Unless you had this app running on Vercel before, the chances of this being related to this sveltekit update are not likely