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

Environment

  • Operating System: Windows_NT
  • Node Version: v18.15.0
  • Nuxt Version: 3.4.3
  • Nitro Version: 2.3.3
  • Package Manager: npm@9.6.2
  • Builder: vite
  • User Config: modules, nitro
  • Runtime Modules: @nuxtjs/i18n@8.0.0-beta.11
  • 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

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 11
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Bump this issue

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.

@ploca14 You can refer to https://github.com/so1ve/dolan-client-meme/commit/64f815fe7e689fa02b5538f6884590a8ebb682ba


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

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

Still an issue in beta 12

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

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)

@pperzyna

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

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

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