question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kazuponcommented, Dec 24, 2020

@frandiox @gurumusch

I’ve had been supported vue-i18n for CSP env. you can vue-i18n-next latest version.

To make it work in the CSP environment, you need to import the runtime-only module provided by vue-i18n-next. Also, since it’s runtime only, locale messages must be pre-compiled.

In general vue application, we bundle using the bundler such as webpack to build vue application. In intlify project, for each bundler, we provide the following:

You can precompile and bundle i18n resource / i18n custom blocks by configuring them in your bundler.

for more details, you can refer to the following documentation and examples:

2reactions
kazuponcommented, Nov 29, 2020

@frandiox Hi! Thank you for your feedback!

I know vitedege & vite-ssr. I think it’s very EXCITING!

A workaround for this problem is that, like Vue’s SSR, vue-i18n need to provide a function like createSSRI18n or renderToString. But unfortunately, it doesn’t look like we’re going to be able to provide it anytime soon.

As for the current development of vue-i18n-next, the implementation is complete. We will be releasing vue-i18n@v9-rc and vue-i18n@v9 with documentation coming soon.

I’m also very interested in edge computing. I have some ideas for an i18n / l10n solution for edge computing. So we’ll continue to work on them. 💪

Read more comments on GitHub >

github_iconTop Results From Across the Web

Examples · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment ...
Read more >
Cloudflare Workers Crash Course | Deploy Your Website with ...
Learn Full Stack Development on codedamn: https://cdm.sh/fullstackTimestamps0:00 Teaser0:44 Video Starts1:14 Installing Wrangler3:02 ...
Read more >
Server-Side Rendering (SSR) Vue.js Application to Cloudflare ...
In this article, we will publish a full-featured, server-side rendered (SSR) Vue application to Cloudflare Workers. But before we begin, let's talk about ......
Read more >
Server-side Tagging In Google Tag Manager - Simo Ahava
You can run a fully functional digital analytics and marketing setup without loading any third-party code in the user's browser or device. With ......
Read more >
21 Performance Optimization Techniques for React Apps
While this will lead to a faster user interface without specifically optimizing for performance for many cases, there are ways where you can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found