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

Module breaks Nuxt 3 build for Cloudflare Pages (Cannot read properties of undefined (reading 'split')) #2031

Closed
AlexDicy opened this issue May 1, 2023 · 16 comments
Labels
cloudflare ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8

Comments

@AlexDicy
Copy link

AlexDicy commented May 1, 2023

Environment

  • Operating System: Windows_NT
  • Node Version: v18.15.0
  • Nuxt Version: 3.4.3
  • Nitro Version: 2.3.3
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: modules, nitro
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

Repo: https://github.com/AlexDicy/nuxt-18n-cf-pages-reproduction

https://stackblitz.com/github/AlexDicy/nuxt-18n-cf-pages-reproduction?file=README.md

Describe the bug

As soon as the module is added to the project the build target Cloudflare Pages stops working because a dependency (readdirp) is executed in the build, causing the preview/deployment to fail.

readdirp tries to access process.versions.node.split which doesn't exist in a Cloudflare Worker enviroinment

Additional context

The bug has been introduced in beta-11

Logs

[mf:err] TypeError: Cannot read properties of undefined (reading 'split')
    at D:\Documents\IdeaProjects\Dicy\nuxt-18n-cf-pages-reproduction\node_modules\readdirp\index.js:33:42
    at SourceTextModule.evaluate (node:internal/vm/module:226:23)
    at VMScriptRunner.runAsModule (C:\Users\Alex\AppData\Local\npm-cache\_npx\32026684e21afda6\node_modules\@miniflare\runner-vm\src\index.ts:40:18)
    at VMScriptRunner.run (C:\Users\Alex\AppData\Local\npm-cache\_npx\32026684e21afda6\node_modules\@miniflare\runner-vm\src\index.ts:86:17)
    at Miniflare.#reload (C:\Users\Alex\AppData\Local\npm-cache\_npx\32026684e21afda6\node_modules\@miniflare\core\src\index.ts:790:13)
    at Miniflare.getPlugins (C:\Users\Alex\AppData\Local\npm-cache\_npx\32026684e21afda6\node_modules\@miniflare\core\src\index.ts:1033:5)
    at createServer (C:\Users\Alex\AppData\Local\npm-cache\_npx\32026684e21afda6\node_modules\@miniflare\http-server\src\index.ts:362:19)
    at startServer (C:\Users\Alex\AppData\Local\npm-cache\_npx\32026684e21afda6\node_modules\@miniflare\http-server\src\index.ts:469:18)
    at main (file:///C:/Users/Alex/AppData/Local/npm-cache/_npx/32026684e21afda6/node_modules/wrangler/miniflare-dist/index.mjs:6374:22)
    at file:///C:/Users/Alex/AppData/Local/npm-cache/_npx/32026684e21afda6/node_modules/wrangler/miniflare-dist/index.mjs:6442:1
@kazupon kazupon added the v8 label May 5, 2023 — with Volta.net
@yankeguo
Copy link

yankeguo commented May 9, 2023

I have encountered a similar issue.

@yankeguo
Copy link

yankeguo commented May 9, 2023

To be clear, it's a runtime exception, not a build-time exception. Cloudflare Pages uses a standard node/npm environment for building.

@yankeguo
Copy link

yankeguo commented May 9, 2023

Seems chokidar introduced readdirp, but chokidar is a cross-platform file watching library, should never appear in production build

@kazupon kazupon added 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage and removed pending triage labels May 10, 2023 — with Volta.net
@suzukey
Copy link

suzukey commented May 11, 2023

I encountered the same issue too.
I think this issue is related to #1993

@yankeguo
Copy link

I created an i18n plugin by myself, surprisingly it works well

@mattgrah-am
Copy link

Still an issue in beta 12

@pperzyna
Copy link

@guoyk93 Could you share your code?

@yankeguo
Copy link

@pperzyna

https://gist.github.com/guoyk93/b09d964fcb72a6905df25fe86474c0f6

It's a very primitive implementation, but works well enough for me.

@RealHinome
Copy link

Hey, I got the same issue, but for Cloudflare Workers. Hope this'll patched in new version!

@kazupon kazupon added the cloudflare label May 24, 2023 — with Volta.net
@so1ve
Copy link
Contributor

so1ve commented May 31, 2023

I did some investigations: this issue is introduced in #1938. It upgraded @intlify/bundle-utils and seemed to be the cause of this issue

@so1ve
Copy link
Contributor

so1ve commented May 31, 2023

FYI to fix this issue temporarily: use a custom rollup plugin to replace process.versions.node with a pre-defined value like JSON.stringify(process.versions.node)

@ploca14
Copy link

ploca14 commented Jun 1, 2023

@so1ve

FYI to fix this issue temporarily: use a custom rollup plugin to replace process.versions.node with a pre-defined value like JSON.stringify(process.versions.node)

Can you share how you setup the rollup plugin?

@so1ve
Copy link
Contributor

so1ve commented Jun 1, 2023

@ploca14 You can refer to so1ve/dolan-client-meme@64f815f


Update: This commit fixed this issue but comes with another issue 😅

image

I have to downgrade this module again

It seemed that i18n module bundles some unused dependencies which will break the code

@LuckyWraptor
Copy link

Bump this issue

@kazupon kazupon added ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf and removed 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Jun 24, 2023 — with Volta.net
Copy link
Collaborator

kazupon commented Jul 17, 2023

This issue was fixed since @intlify/bundle-utils is no longer bundled on the server side as of v8.0.0-beta.13.
If you have still issue, please reply.

@AlexDicy
Copy link
Author

Indeed, the issue has been fixed. Thank you for the notice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloudflare ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8
Projects
None yet
Development

No branches or pull requests

10 participants