Skip to content
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

devalue cause crash on Netlify after update #6462

Closed
wentallout opened this issue Aug 31, 2022 · 37 comments
Closed

devalue cause crash on Netlify after update #6462

wentallout opened this issue Aug 31, 2022 · 37 comments
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-netlify
Milestone

Comments

@wentallout
Copy link

wentallout commented Aug 31, 2022

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",

@kiosion
Copy link

kiosion commented Aug 31, 2022

+1, after a @sveltejs/kit upgrade from 1.0.0-next.445 1.0.0-next.449 production builds on Netlify crash on load with

Error - No "exports" main defined in /var/task/node_modules/devalue/package.json

Edit: Seems to be caused by #6318 bumping devalue's version to 3.1.2

@wentallout wentallout changed the title crashed on Netlify after update devalue cause crash on Netlify after update Aug 31, 2022
@MajorBreakfast
Copy link

Screen Shot 2022-08-31 at 20 21 00

Just to visualize the error :)

@rowantrollope
Copy link

Having the same issue on vercel

@MajorBreakfast
Copy link

MajorBreakfast commented Sep 1, 2022

Looking at the package.json of devalue, it does not have a main field. My (unconfirmed) guess is that this is the issue

https://github.com/Rich-Harris/devalue/blob/master/package.json

Edit: tried patching the package via a diff applied using patch-package. it didn't yield results unfortunately

@demetrius-mp
Copy link

same here when deploying to netlify.
i tried deploying to vercel, but i had the following error

> Using @sveltejs/adapter-vercel
--
15:29:07.600 | error during build:
15:29:07.600 | Error: Failed to parse /vercel/path0/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html as script:
15:29:07.600 | Unexpected token (1:0)
15:29:07.600 | at Object.analyze [as default] (/vercel/path0/node_modules/@vercel/nft/out/analyze.js:226:30)
15:29:07.601 | at Job.emitDependency (/vercel/path0/node_modules/@vercel/nft/out/node-file-trace.js:304:52)
15:29:07.601 | at async /vercel/path0/node_modules/@vercel/nft/out/node-file-trace.js:335:21
15:29:07.601 | at async Promise.all (index 30)
15:29:07.601 | at async Job.emitDependency (/vercel/path0/node_modules/@vercel/nft/out/node-file-trace.js:310:9)
15:29:07.601 | at async /vercel/path0/node_modules/@vercel/nft/out/node-file-trace.js:335:21
15:29:07.601 | at async Promise.all (index 1)
15:29:07.601 | at async Job.emitDependency (/vercel/path0/node_modules/@vercel/nft/out/node-file-trace.js:310:9)
15:29:07.601 | at async /vercel/path0/node_modules/@vercel/nft/out/node-file-trace.js:335:21
15:29:07.601 | at async Promise.all (index 6)

could it be for the same reason?

repo that caused the issue on both netlify and vercel

@MajorBreakfast
Copy link

@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

@rowantrollope
Copy link

The error I'm seeing on verbal is:

"SyntaxError: Named export 'devalue' not found. The requested module 'devalue' is a CommonJS module, which may not support all module.exports as named exports."

Screenshot attached.

Screenshot 2022-09-01 at 1 49 28 PM

@geoffrich
Copy link
Member

This issue is happening because the new version of devalue is ESM-only, and Netlify is trying to require 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:

  1. Configure Netlify to bundle your functions with esbuild. In a netlify.toml at the root of the project:
[build]
  command = "npm run build"
  publish = "build"

[functions]
  node_bundler = "esbuild" # temporary workaround for https://github.com/sveltejs/kit/issues/6462
  1. Deploy using Netlify edge functions. In your svelte.config.js:
import netlify from '@sveltejs/adapter-netlify';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	kit: {
+		adapter: netlify({ edge: true })
-		adapter: netlify()
	}
};

export default config;

@geoffrich
Copy link
Member

For those reporting a similar issue on Vercel -- can you provide a repro? I was able to reproduce this issue with a fresh demo project on Netlify, but not on Vercel.

@demetrius-mp
Copy link

For those reporting a similar issue on Vercel -- can you provide a repro? I was able to reproduce this issue with a fresh demo project on Netlify, but not on Vercel.

the issue i was having on vercel is not related to devalue, but to this

@xpat
Copy link

xpat commented Sep 1, 2022

Also crashes for me on adapter-node.

import devalue from "devalue";
       ^^^^^^^
SyntaxError: The requested module 'devalue' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:127:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
    at async Promise.all (index 0)

In another issue related to this, it was suggested that the problem could be fixed by setting "true" at "esModuleInterop": true,
but my tsconfig.json already had it set to true.

cat tsconfig.json 
{
        "extends": "./.svelte-kit/tsconfig.json",
        "compilerOptions": {
                "moduleResolution": "node",
                "module": "es2020",
                "lib": ["es2020", "DOM"],
                "target": "es2020",
                /**
                svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
                to enforce using \`import type\` instead of \`import\` for Types.
                */
                "importsNotUsedAsValues": "error",
                "isolatedModules": true,
                "resolveJsonModule": true,
                /**
                To have warnings/errors of the Svelte compiler at the correct position,
                enable source maps by default.
                */
                "sourceMap": true,
                "esModuleInterop": true,
                "skipLibCheck": true,
                "forceConsistentCasingInFileNames": true,
                "baseUrl": ".",
                "allowJs": true,
                "checkJs": true,
                "paths": {
                        "$lib": ["src/lib"],
                        "$lib/*": ["src/lib/*"],
                        "$img": ["src/images"]
                }
        },
        "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"]
}

@Rich-Harris
Copy link
Member

The issue described in the OP is happening because Netlify doesn't support ESM (netlify/zip-it-and-ship-it#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 default zisi (zip-it-and-ship-it), esbuild bundles everything to a single file rather than just zipping up stuff in node_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 — use esbuild within the adapter to bundle everything in devDependencies, but leave prod dependencies unbundled. If you're using zisi then native dependencies will continue to work, and if you're using esbuild 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...

import devalue from 'devalue'

...it means it's expecting devalue@2, not devalue@3 (which uses a named export).

@rowantrollope seems like you have the opposite problem — that code expects devalue@3, but you might have devalue@2 installed somehow?

@benmccann benmccann added bug Something isn't working pkg:adapter-netlify p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. labels Sep 2, 2022
@benmccann benmccann added this to the 1.0 milestone Sep 2, 2022
@rowantrollope
Copy link

rowantrollope commented Sep 2, 2022 via email

@StephenGunn
Copy link

StephenGunn commented Sep 2, 2022

@geoffrich Thanks for that fix.. I tried it and it kind of worked. Most of the dynamic routes that were broken started working.. But other things started breaking. A few dynamic routes just wouldn't load on the live server. They would 404 and the data requests wouldn't even hit my backend.

They all built and ran fine locally with pnpm build / pnpm preview.

Just wanted to give a heads up. I obviously have tempered expectations using software that's in beta and am fine waiting for a fix.

Let me know if there is anything I can do for you to help troubleshoot.

Thanks for all your hard work :)

@MajorBreakfast
Copy link

MajorBreakfast commented Sep 2, 2022

I think I'm back in business on Netlify.

After doing both steps it works. My ssr.noExternal array already contained other ESM packages before that (due to lack of ESM support on Netlify)

peterwilmshurst added a commit to peterwilmshurst/svelte-netlify that referenced this issue Sep 2, 2022
dkmooers added a commit to dkmooers/reforestation-simulator that referenced this issue Sep 2, 2022
@pilcrowonpaper
Copy link

I was able to get something deployed by adding devalue to ssr.noExternal, though I'm not sure if everything works

elron added a commit to elron/svelte-interactive-carousel that referenced this issue Sep 3, 2022
janosh added a commit to janosh/svelte-multiselect that referenced this issue Sep 3, 2022
until sveltejs/kit#6462 resolves
static

> Using @sveltejs/adapter-static fails with error
  @sveltejs/adapter-static: all routes must be fully prerenderable (unless using the 'fallback' option — see https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode). Try adding `export const prerender = true` to your root layout — see https://kit.svelte.dev/docs/page-options#prerender for more details

run CI tests on both linux and windows using matrix strategy
janosh added a commit to janosh/svelte-multiselect that referenced this issue Sep 3, 2022
* update deps

* set vite dev and preview ports to 3000

* sveltekit '$app/env' renamed to '$app/environment'

* determine active option not by label but by index in array of matchingOptions

replace setOptionsVisible(bool) with open_dropdown() and close_dropdown()
trigger close_dropdown() on touchstart outside (as well as click outside), select wasn't closing on mobile without that
rename prop showOptions to open
add props focusInputOnSelect: boolean | 'desktop' and breakpoint = 800

* document new props activeIndex, focusInputOnSelect, breakpoint in readme

* document showOptions -> open rename in readme under recent breaking changes

* improve description of Slot Components example

* change web server command for testing to yarn dev (from server)

* fix 2 broken tests using page.goto({ waitUntil: `networkidle` })

* switch to adapter-netlify for time being and use edge

until sveltejs/kit#6462 resolves
static

> Using @sveltejs/adapter-static fails with error
  @sveltejs/adapter-static: all routes must be fully prerenderable (unless using the 'fallback' option — see https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode). Try adding `export const prerender = true` to your root layout — see https://kit.svelte.dev/docs/page-options#prerender for more details

run CI tests on both linux and windows using matrix strategy

* tweak focusInputOnSelect readme docs
18kimn added a commit to antievictionmappingproject/www that referenced this issue Sep 4, 2022
suda added a commit to gaia-charge/website that referenced this issue Sep 7, 2022
0xnook added a commit to 0xnook/token-delegation-interface that referenced this issue Sep 8, 2022
@suryamsj
Copy link

suryamsj commented Sep 8, 2022

I'm also having the same problem. But when I change vite.config.js to like this

const config = {
	plugins: [sveltekit()],
	ssr: {
		noExternal: ['devalue']
	}
};

everything is working normally and everything seems to be working

valeriegc added a commit to valeriegc/triviagame that referenced this issue Sep 10, 2022
valeriegc added a commit to valeriegc/triviagame that referenced this issue Sep 10, 2022
efedorenko added a commit to efedorenko/accessiblepalette that referenced this issue Sep 10, 2022
SaschaDoe added a commit to SaschaDoe/RandomTableApp that referenced this issue Sep 11, 2022
rhersen pushed a commit to rhersen/timpris that referenced this issue Sep 12, 2022
@geoffrich
Copy link
Member

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 or svelte.config.js and update to the latest Netlify adapter to see if that fixes your issue?

@secondl1ght
Copy link

Awesome - just updated packages to latest and removed the workaround from netlify.toml and it deploys normally again. Thanks!

@sonyarianto
Copy link

ok, I removed the work around on vite.config.js and build on Vercel and it works :) Thank you. @geoffrich

@wentallout
Copy link
Author

I updated all the packages to newest and everything works normally.

@geoffrich
Copy link
Member

Closing since the issue appears to have been fixed.

@tedsteen
Copy link

Hmm, what am I missing?

My package.json contains

"@sveltejs/adapter-netlify": "next",
"@sveltejs/kit": "next",

My netlify.toml looks like this

[build]
  command = "npm run build"
  publish = "build"

[[plugins]]
package = 'netlify-plugin-contextual-env'

and my vite.config.js

import { sveltekit } from '@sveltejs/kit/vite';
import { imagetools } from 'vite-imagetools';

/** @type {import('vite').UserConfig} */
const config = {
	plugins: [sveltekit(), imagetools()],
	resolve: {
		preserveSymlinks: true
	}
};

export default config;

I did npm update and I still get Error - No "exports" main defined in /var/task/node_modules/devalue/package.json when I deploy to netlify.

@geoffrich
Copy link
Member

@tedsteen can you paste the output of npx envinfo --npmPackages "{svelte,@sveltejs/*,vite}"?

I can't repro on the SvelteKit demo app - can you provide a minimal repo reproducing the issue?

@MajorBreakfast
Copy link

MajorBreakfast commented Sep 13, 2022

BTW just tested out of curiosity what happens if [email protected] (not 3.1.3) is installed: I'm seeing that the older version works now as well. With the latest Netlify adapter there's no problem anymore (on my end).

@tedsteen Just "next" in the package.json isn't forceful enough. If a node_modules/ folder or a package-lock.json still exist, it will pick the same versions as last time. I can recommend using the tool npm-check-updates for updating the package.json. Or alternatively delete the node_modules/ folder and package-lock.json, run npm i and take a look at the git diff of the package-lock.json to see whether it updated all the desired packages.

@tedsteen
Copy link

npx envinfo --npmPackages "{svelte,@sveltejs/*,vite}"

❯ npx envinfo --npmPackages "{svelte,@sveltejs/*,vite}"

npmPackages:
@sveltejs/adapter-netlify: next => 1.0.0-next.77
@sveltejs/kit: next => 1.0.0-next.481
svelte: ^3.49.0 => 3.50.1

@tedsteen
Copy link

tedsteen commented Sep 14, 2022

Just "next" in the package.json isn't forceful enough. If a node_modules/ folder or a package-lock.json still exist, it will pick the same versions as last time. I can recommend using the tool npm-check-updates for updating the package.json. Or alternatively delete the node_modules/ folder and package-lock.json, run npm i and take a look at the git diff of the package-lock.json to see whether it updated all the desired packages.

Didn't make a difference (it seems like npm update does update next versions?)

@tedsteen
Copy link

I'm not sure what happened, but now it works and I can't seem to revert to a broken version.

@wvhulle
Copy link

wvhulle commented Oct 6, 2022

Putting "devalue": "^3.1.3" in my dependencies section of package.json fixed it.

@rowantrollope
Copy link

rowantrollope commented Oct 11, 2022 via email

@janosh
Copy link
Contributor

janosh commented Oct 23, 2022

Anyone else still/again seeing this in netlify builds with adapter-static during pre-rendering?

9:40:24 PM: .svelte-kit/output/server/chunks/hooks.js 0.00 KiB
9:40:24 PM: TypeError: devalue.uneval is not a function
9:40:24 PM: at render_response (file:///opt/build/repo/.svelte-kit/output/server/index.js:1111:31)
9:40:24 PM: at async render_page (file:///opt/build/repo/.svelte-kit/output/server/index.js:1501:12)
9:40:24 PM: at async resolve (file:///opt/build/repo/.svelte-kit/output/server/index.js:1994:22)
9:40:24 PM: at async respond (file:///opt/build/repo/.svelte-kit/output/server/index.js:2032:22)
9:40:24 PM: at async visit (file:///opt/build/repo/node_modules/.pnpm/@sveltejs[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:226:20)

https://app.netlify.com/sites/svelte-bricks/deploys/634f7f8bafaf8e0009a09e15#L153

@brittneypostma
Copy link
Contributor

@janosh I am currently using adapter-static on Netlify and not seeing this error. If you still need help, post your netlify.toml file if you have one, your svelte.config.js , and output of npx envinfo --npmPackages "{svelte,@sveltejs/*,vite}".

@janosh
Copy link
Contributor

janosh commented Nov 2, 2022

@brittneypostma I just pnpm add -D devalue to solve the problem. But would be interesting to find out why devalue wasn't installed automatically.

EthanThatOneKid added a commit to EthanThatOneKid/acmcsuf.com that referenced this issue Nov 13, 2022
suda added a commit to gaia-charge/website that referenced this issue Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-netlify
Projects
None yet
Development

No branches or pull requests