Skip to content

Crash when running on Cloudflare Worker (SSR) due to string evaluation #198

@frandiox

Description

@frandiox

Hello @kazupon ! I'm trying out vue-i18n with Vitedge, which is doing SSR using Vite. It works well when running in a Node.js server.
However, it crashes when running in a Cloudflare Worker environment. I'm not providing a repro link since you would need a Cloudflare account and all of that, but I'm giving more info in the following.

vue & vue-i18n version

ex:

  • vue: 3.0.x
  • vue-i18n: 9.0.0-beta.8

Steps to reproduce

Use vue-i18n in any Vue app running on a Cloudflare Worker (SSR, different from Node.js environment).

What is Expected?

It should work.

What is actually happening?

It crashes with error Code generation from strings disallowed for this context when the t function is called. This error means that eval and related unsafe calls are not allowed in this environment.
After researching for a while, I found that the line that makes it crash is here: https://github.com/intlify/vue-i18n-next/blob/master/src/message/compiler.ts#L73

This new Function('...') is basically a different form of eval, and such a thing is forbidden in a worker environment due to security reasons.

Do you think this could be implemented in a different way without relying on eval? Or any other workaround to support this environment?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: ImprovementIncludes backwards-compatible fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions