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

I can't use I18n in Cloudflare Workers. #54

Closed
q351941406 opened this issue Oct 30, 2024 · 1 comment
Closed

I can't use I18n in Cloudflare Workers. #54

q351941406 opened this issue Oct 30, 2024 · 1 comment

Comments

@q351941406
Copy link

I know that local folders cannot be accessed in Cloudflare Workers, so I didn't use the loadLocalesDir parameter. I plan to load the translation data directly, but it still results in an error. If I comment out this code, the program runs normally.

const i18n = new I18n<TelegramContext>({
  defaultLocale: "zh",
});

`✘ [ERROR] service core:user:main-dev: Uncaught ReferenceError: __dirname is not defined

at null.<anonymous> (index.js:15655:180) in

node_modules/@deno/shim-deno/dist/deno/stable/variables/mainModule.js
at null. (index.js:32:52) in __require2
at null. (index.js:17688:27) in
node_modules/@deno/shim-deno/dist/deno/stable/variables.js
at null. (index.js:32:52) in __require2
at null. (index.js:22538:26) in
node_modules/@deno/shim-deno/dist/deno/stable/functions.js
at null. (index.js:32:52) in __require2
at null. (index.js:22980:18) in node_modules/@deno/shim-deno/dist/deno/stable/main.js
at null. (index.js:32:52) in __require2
at null. (index.js:23018:18) in node_modules/@deno/shim-deno/dist/deno.js
at null. (index.js:32:52) in __require2

✘ [ERROR] The Workers runtime failed to start. There is likely additional logging output above.`

It should be related to the code below, which I saw in utils.js.
const contents = await dntShim.Deno.readFile((0, deps_js_1.join)(path, excludeRoot));

IMAGE 2024-10-31 05:02:11

@KnorpelSenf KnorpelSenf transferred this issue from grammyjs/grammY Oct 30, 2024
@KnorpelSenf
Copy link
Member

CFW has its own custom JS runtime and we currently do not build for it. That being said, you can most likely get the Deno version to work on it, such as by taking the script file from https://raw.githubusercontent.com/grammyjs/i18n/refs/heads/main/src/mod.ts and putting into https://bundle.deno.dev which gives you this file (zipped so that GH supports it): i18n-cfw.zip

We are going to migrate the entire grammY ecosystem to https://jsr.io which will give us full CFW support for all plugins for free. This is a lot of work so it will take some time, but it is going to happen.

This is tracked in grammyjs/grammY#559. I will close this issue in favour of that one, as we are not going to migrate our build system twice just to fix this sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants