unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.82k stars 492 forks source link

Cloudflare Pages build fails. Cannot resolve "unenv/runtime/node/process/index/" #2631

Open ryoid opened 1 month ago

ryoid commented 1 month ago

Environment

Reproduction

Run build in Stackblitz

Made from starter template and adding readable-stream

Describe the bug

Unable to build for Cloudflare Pages with readable-stream

Additional context

Related Issues

Logs

[12:58:23 AM]  ERROR  Cannot resolve "unenv/runtime/node/process/index/" from "/home/ryoid/nitro-cfpages-unenv-repo/node_modules/.pnpm/readable-stream@4.4.0/node_modules/readable-stream/lib/internal/streams/pipeline.js" and externals are not allowed!

  at Object.resolveId (node_modules/.pnpm/nitropack@2.9.7/node_modules/nitropack/dist/nitro.mjs:2003:17)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/rollup@4.19.0/node_modules/rollup/dist/es/shared/node-entry.js:19733:28)
  at async resolveId (node_modules/.pnpm/rollup@4.19.0/node_modules/rollup/dist/es/shared/node-entry.js:18414:26)
  at async ModuleLoader.resolveId (node_modules/.pnpm/rollup@4.19.0/node_modules/rollup/dist/es/shared/node-entry.js:18817:15)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/rollup@4.19.0/node_modules/rollup/dist/es/shared/node-entry.js:19733:28)
  at async resolveId (node_modules/.pnpm/rollup@4.19.0/node_modules/rollup/dist/es/shared/node-entry.js:18414:26)
  at async ModuleLoader.resolveId (node_modules/.pnpm/rollup@4.19.0/node_modules/rollup/dist/es/shared/node-entry.js:18817:15)
  at async eval (node_modules/.pnpm/@rollup+plugin-commonjs@25.0.8_rollup@4.19.0/node_modules/@rollup/plugin-commonjs/dist/es/index.js:800:16)
  at async eval (node_modules/.pnpm/@rollup+plugin-commonjs@25.0.8_rollup@4.19.0/node_modules/@rollup/plugin-commonjs/dist/es/index.js:792:32)
ryoid commented 1 month ago

After some tinkering it seems like the issue is because the readable-stream library use require('process/'), with the trailing slash. Patching unenv to also include process/ allows build to complete. But I'm not sure if there any implications of this.

Alternatively aliasing it also works.

alias: {
    "process/": "process"
}
Dmytro-Tihunov commented 4 weeks ago

hey, have you managed fix it?