Solution after vuei18n reports error in production environment

Problems with Vue3 i18n in production environment!

1#

When using CSP in a Vue3 vite build, this error is thrown: EvalError:
Denied string evaluation as JavaScript because 'unsafe-eval' is not a permitted script source in the following content security policy directive: 'script-src 'self' 'nonce-FMO9QrSTmJ76tL87'

This error occurs because vue i18n uses eval writing and new function to improve performance when packaging. When deployed to a production environment, there is a certain probability of causing the above problems, **

image.png

After searching countless methods, I finally found the same problem as me in the latest issues of the official plug-in.

It is strongly recommended that if you encounter problems with the plug-in, go to github to find out if there is a similar method! ! !

Re-download vue i18n and update the version to 9 or above pnpm i -S [email protected]

Then download the unplugin-vue-i18n plug-in

npm install @intlify/unplugin-vue-i18n --save

Join the following

image.png

1d1ipl5r.png

Under resolve at the same level as plugins, add the define option and enable jit compilation.

image.png

After that, packaging will be no problem, and there is no need to add any new configurations on the server side. If you have any questions, you can ask them and they will be answered in seconds.

Okay, everyone, it’s original, please indicate the source when reprinting it.

Guess you like

Origin blog.csdn.net/qq_40606563/article/details/132293376