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

[wrangler] "default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs" #260

Open
jvbianchi opened this issue Jun 16, 2024 · 9 comments · Fixed by #261
Labels
bug Something isn't working

Comments

@jvbianchi
Copy link

jvbianchi commented Jun 16, 2024

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
@jvbianchi jvbianchi added the bug Something isn't working label Jun 16, 2024
@pi0
Copy link
Member

pi0 commented Jun 17, 2024

Are you force resolving unenv to nighyly version in your Nitro project?

@jvbianchi
Copy link
Author

jvbianchi commented Jun 17, 2024

No , I just install nuxt using Bun with this command:

bun create cloudflare@latest my-nuxt-app -- --framework=nuxt

@pi0
Copy link
Member

pi0 commented Jun 17, 2024

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)

@jvbianchi
Copy link
Author

jvbianchi commented Jun 17, 2024

I just saw, It's one of wrangler's depencies:

[email protected]:
  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:[email protected]"
    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

@pi0 pi0 changed the title "default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs" [wrangler] "default" is not exported by "node_modules/unenv/runtime/polyfill/process.mjs" Jun 17, 2024
@IgorMinar
Copy link
Collaborator

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

@IgorMinar
Copy link
Collaborator

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).

@jvbianchi
Copy link
Author

jvbianchi commented Jun 17, 2024

When I install unenv as a dev dependency (version 1.9.0) the error goes way.

@IgorMinar
Copy link
Collaborator

@jvbianchi which suggests that bun's package hoisting is the culprit here.

@pi0
Copy link
Member

pi0 commented Jun 18, 2024

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants