s00d / nuxt-i18n-micro

Nuxt I18n Micro is a fast, simple, and lightweight internationalization (i18n) module for Nuxt
https://s00d.github.io/nuxt-i18n-micro/
MIT License
87 stars 11 forks source link

cloudflare worker ERROR: Code generation from strings disallowed for this context #19

Closed Cleaner10x closed 1 month ago

Cleaner10x commented 1 month ago

Describe the bug 500 error of "Code generation from strings disallowed for this context" in cloudflare worker

To Reproduce

  1. npx nuxi@latest init test
  2. pnpm -D install nuxt-i18n-micro
  3. add nuxt-i18n-micro as the modules to nuxt.config.ts
  4. NITRO_PRESET=cloudflare-pages npx nuxt build
  5. npx wrangler pages dev dist then we will see the error message from the page.

Expected behavior add support of cloudflare worker

Desktop (please complete the following information):

s00d commented 1 month ago

Hi, I’ve never worked with Cloudflare Pages before. I’ve made a fix(1.19.0) that should, in theory, add all routes to the pre-rendering, but I’m not sure if I did everything correctly. Please let me know if there are any issues. If needed, you could create a simple project example and describe the problem so I can understand how to fix it.

Cleaner10x commented 1 month ago

I tested with the latest 1.19.2, but it shows the same error. it seems that Cloudflare has some restrictions to the use of JS functions.

you could just add "NITRO_PRESET=cloudflare-pages" before the "nuxt build" to build a cloudflare version of the dist. and run "npx wrangler pages dev dist" to test with the new dist.

for example: in your shell, run NITRO_PRESET=cloudflare-pages npx nuxt build then npx wrangler pages dev dist

fyi: https://developers.cloudflare.com/workers/runtime-apis/web-standards/#javascript-standards https://github.com/cloudflare/next-on-pages/issues/615

s00d commented 1 month ago
image

I tried building the playground and running it, there were no errors. Can you provide an example of the code?

Cleaner10x commented 1 month ago

the build and starting of the server does not show the error. but when you press the key "b" or open the "http://localhost:8788", then you should see the error in the browser and the console log from the server.

s00d commented 1 month ago

I managed to track down the issue, and it seems to have been related to Nuxt. I reworked the route-adding logic a bit, although nothing fundamentally changed — the routes are now added in batches rather than one by one. Afterward, I deleted the .nuxt and dist folders, and everything started working fine. I’m still not entirely sure what caused the problem or why it’s working now, but try using the latest version, v1.21.3.

Cleaner10x commented 1 month ago

After upgrade all the packages to the latest, I'm very sorry to tell you, with the ".nuxt" and "dist" deleted, and "npx nuxt cleanup". It still shows the error...

dependencies:
nuxt 3.13.2
vue 3.5.10
vue-router 4.4.5

devDependencies:
nuxt-i18n-micro 1.21.3
[wrangler:inf] Ready on http://localhost:8788
[wrangler:inf] GET / 500 Internal Server Error (41ms)
[wrangler:inf] GET /_locales/general/en/data.json 200 OK (3ms)
[wrangler:inf] GET /_locales//en/data.json 200 OK (1ms)
[wrangler:inf] GET / 500 Internal Server Error (13ms)
[wrangler:inf] GET /_locales/general/en/data.json 200 OK (3ms)
[wrangler:inf] GET /_locales//en/data.json 200 OK (2ms)
[wrangler:inf] GET /_nuxt/builds/meta/53afada7-303e-4a9e-bc1e-06a1887f7f62.json 200 OK (18ms)
[wrangler:inf] GET / 500 Internal Server Error (10ms)
[wrangler:inf] GET /_locales/general/en/data.json 200 OK (3ms)
[wrangler:inf] GET /_locales//en/data.json 200 OK (2ms)
[wrangler:inf] GET / 500 Internal Server Error (13ms)
[wrangler:inf] GET /_locales/general/en/data.json 200 OK (2ms)
[wrangler:inf] GET /_locales//en/data.json 200 OK (2ms)
s00d commented 1 month ago

Can you send me the code? I can't find the problem this way.

Cleaner10x commented 1 month ago

https://file.io/GTbNZ3HTlvTB https://temp-file-share.web.app/d/FC6f-6NYq

Please try with:

npm -g install wrangler
pnpm i
NITRO_PRESET=cloudflare-pages npx nuxt build
npx wrangler pages dev dist

Then, press "b" to start see the client shows error.

s00d commented 1 month ago

https://file.io/cGfYXYoRivbv https://temp-file-share.web.app/d/QaPP-tKVo

Without includeDefaultLocaleRoute: true, it doesn't seem to work. I haven't looked into the reason, but I don't think it's critical.

All you need to do is create a new page (I removed app.vue—it might cause issues, so I recommend doing the same) and configure the project accordingly.

s00d commented 1 month ago

Closing due to no response.