[wrangler] "default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs"
jvbianchi opened this issue Β· comments
Environment
cloudflare pages
Reproduction
try to deploy Nuxt to cloudflare pages using the /server/api/hello.ts folder with a simple test
export default defineEventHandler((_event) => {
return {
hello: "Hello from Server!!!",
};
});
Describe the bug
"default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs"
Additional context
unenv-nightly version 1.10.0-1717606461.a117952
Logs
19:41:10.273 [info] [nitro] Building Nuxt Nitro server (preset: `cloudflare-pages`)
19:41:11.891 node_modules/std-env/dist/index.mjs (1:9): Error when using sourcemap for reporting an error: Can't resolve original location of error.
19:41:11.891 [error] [nitro] RollupError: node_modules/std-env/dist/index.mjs (1:9): "default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs", imported by "node_modules/std-env/dist/index.mjs".
19:41:11.892
19:41:11.892
19:41:11.892 1: import { default as process } from 'unenv/runtime/polyfill/process';
19:41:11.892 ^
19:41:11.892 2:
19:41:11.892 3: const r=Object.create(null),E=e=>globalThis.process?.env||globalThis._importMeta_.env||globalThis.Deno?.env.toObject(...
19:41:11.893 [error] node_modules/std-env/dist/index.mjs (1:9): "default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs", imported by "node_modules/std-env/dist/index.mjs".
19:41:11.894 at getRollupError (node_modules/rollup/dist/es/shared/parseAst.js:396:41)
19:41:11.894 at error (node_modules/rollup/dist/es/shared/parseAst.js:392:42)
19:41:11.894 at Module.error (node_modules/rollup/dist/es/shared/node-entry.js:13858:16)
19:41:11.894 at Module.traceVariable (node_modules/rollup/dist/es/shared/node-entry.js:14306:29)
19:41:11.894 at ModuleScope.findVariable (node_modules/rollup/dist/es/shared/node-entry.js:11984:39)
19:41:11.894 at Identifier.bind (node_modules/rollup/dist/es/shared/node-entry.js:6908:40)
19:41:11.894 at UnaryExpression.bind (node_modules/rollup/dist/es/shared/node-entry.js:4775:23)
19:41:11.894 at BinaryExpression.bind (node_modules/rollup/dist/es/shared/node-entry.js:4775:23)
19:41:11.895 at LogicalExpression.bind (node_modules/rollup/dist/es/shared/node-entry.js:4775:23)
19:41:11.895 at LogicalExpression.bind (node_modules/rollup/dist/es/shared/node-entry.js:4775:23)
19:41:11.895
19:41:11.895 [error] node_modules/std-env/dist/index.mjs (1:9): "default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs", imported by "node_modules/std-env/dist/index.mjs".
19:41:11.930 Failed: Error while executing user command. Exited with error code: 1
Are you force resolving unenv to nighyly version in your Nitro project?
No , I just install nuxt using Bun with this command:
bun create cloudflare@latest my-nuxt-app -- --framework=nuxt
You have mentioned unenv-nightly version 1.10.0-1717606461.a117952
how it is there?
Can you please share npm why unenv
/ pnpm why unenv
(depending on your package manager)
I just saw, It's one of wrangler's depencies:
wrangler@3.60.3:
version "3.60.3"
resolved "https://registry.npmjs.org/wrangler/-/wrangler-3.60.3.tgz"
integrity sha512-a6zn/KFnYaYp3nxJR/aP0TeaBvJDkrrfI89KoxUtx28H7zpya/5/VLu3CxQ3PRspEojJGF0s6f3/pddRy3F+BQ==
dependencies:
unenv "npm:unenv-nightly@1.10.0-1717606461.a117952"
nanoid "^3.3.3"
esbuild "0.17.19"
resolve "^1.22.8"
chokidar "^3.5.3"
miniflare "3.20240610.0"
selfsigned "^2.0.1"
source-map "0.6.1"
blake3-wasm "^2.1.5"
xxhash-wasm "^1.0.1"
path-to-regexp "^6.2.0"
resolve.exports "^2.0.2"
"@cloudflare/kv-asset-handler" "0.3.2"
"@esbuild-plugins/node-globals-polyfill" "^0.2.3"
"@esbuild-plugins/node-modules-polyfill" "^0.2.2"
optionalDependencies:
fsevents "~2.3.2"
It was changed in this commit: cloudflare/workers-sdk@1e68fe5
Interesting. Is this some kind of weird npm package hoisting issue?
I've just tested the repro with pnpm and it works just fine for me, and I see
$ pnpm list --depth=20 unenv unenv-nightly
Legend: production dependency, optional only, dev only
nuxt-app /my-nuxt-app2
dependencies:
nuxt 3.12.2
βββ¬ @nuxt/vite-builder 3.12.2
β βββ¬ h3 1.11.1
β β βββ unenv 1.9.0
β βββ unenv 1.9.0
βββ¬ h3 1.11.1
β βββ unenv 1.9.0
βββ¬ nitropack 2.9.6
β βββ¬ h3 1.11.1
β β βββ unenv 1.9.0
β βββ¬ listhen 1.7.2
β β βββ¬ h3 1.11.1
β β βββ unenv 1.9.0
β βββ unenv 1.9.0
β βββ¬ unstorage 1.10.2
β βββ¬ h3 1.11.1
β β βββ unenv 1.9.0
β βββ¬ listhen 1.7.2
β βββ¬ h3 1.11.1
β βββ unenv 1.9.0
βββ unenv 1.9.0
βββ¬ unstorage 1.10.2
βββ¬ h3 1.11.1
βββ unenv 1.9.0
devDependencies:
h3 1.11.1
βββ unenv 1.9.0
wrangler 3.60.3
βββ unenv-nightly 1.10.0-1717606461.a117952
Could you try to use pnpm or somehow tell bun not to hoist packages (I'm not a bun user, but I hope there is a way to do that).
@pi0 we could try to bundle unenv-nightly into Wrangler but it's tricky because unenv has built-time and runtime component and we currently get the runtime-component from the npm package (the built-time part is already bundled into the wrangler bundle).
When I install unenv as a dev dependency (version 1.9.0) the error goes way.
@jvbianchi which suggests that bun's package hoisting is the culprit here.
Thanks for report dear @jvbianchi
As you have already figured out, adding latest (1.9.x
) version of unenv to your main project dependencies
, devDependencies
(or resolutions
if those won't work will fix the hoisting issue in your project.
For the followup:
- #261 adds back default export but needs a bump in wrangler deps
- Wrangler to update to non nightly dependency of unenv (this is to reduce hoisting issue with
npm:
protocol)