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)

Commits related to this issue

Most upvoted comments

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;

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?

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.

  • @Rich-Harris released devalue@3.1.3 which adds the main field in package.json and I made sure that my package-lock.json specifies the 3.1.3 version (link to commit in devalue repo)
  • I added 'devalue' to the ssr.noExternal array in the Vite config

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)

Hi I am doing like this, refering to this https://github.com/Rich-Harris/devalue/issues/36

  • Remove package-lock.json (because still contains devalue 3.1.2)
  • Remove pnpm-lock.yaml (because still contains devalue 3.1.2)
  • Run pnpm install (will create fresh pnpm-lock.yaml)
  • Edit vite.config.js to this
const config = {
	plugins: [sveltekit()],
	ssr: {
		noExternal: ['devalue']
	}
};
  • Build on Vercel
  • Build success!

+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

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 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?

Screen Shot 2022-08-31 at 20 21 00

Just to visualize the error 😃

@brittneypostma I just pnpm add -D devalue to solve the problem. But would be interesting to find out why devalue 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

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

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