Comments (10)
Hi! Thank you for you reproduction repo quickly.
I looked at your vite.config.
I see that src/locale/index.ts
is now in the transform of i18n resources.
I recommend configuring the include
option to unplugin-vue-i18n
to prevent your application code from being included.
from bundle-tools.
Please could you also give us vite.config?
from bundle-tools.
I've just added the notice docs.
⚠️ NOTE: If you use the js and ts resources formats, set the paths, so your application code is not targeted. We recommend that resources be isolated from the application code.
https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#include
So, close this issue.
Thanks!
from bundle-tools.
Hi!
Thank you for your reproduction!
I've just checked it!
It's rare for this issue to occur.
In generally, when we are using vue-i18n, i18n resources should be organized in a directory such as locales
or lang
.
In that case, the include
option of unplugin-vue-i18n should be set to include: path.resolve(__dirname, 'src/locales/**')
.
With that setting, unplugin-vue-i18n will only transform for 'src/locales/**'
, so you will not have this issue.
But, we should write clearly to docs that we should organize for js
and ts
format resources.
from bundle-tools.
Same issue encountered here. The part before {
is an array. The code transform is buggy in 0.9.1
from bundle-tools.
src/locale/index.ts
import { createI18n } from 'vue-i18n';
export const WHATEVER_THE_FIRST_EXPORT = ['WHATEVER_THE_FIRST_EXPORT'];
const i18n = createI18n({
locale: 'zh-CN',
fallbackLocale: 'en-US',
allowComposition: true,
messages: {
'en-US': {},
'zh-CN': {},
},
});
export default i18n;
Transformed:
export default [
(()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["WHATEVER_THE_FIRST_EXPORT"])};fn.source="WHATEVER_THE_FIRST_EXPORT";return fn;})(),
]{
"locale": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["zh-CN"])};fn.source="zh-CN";return fn;})(),
"fallbackLocale": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["en-US"])};fn.source="en-US";return fn;})(),
"allowComposition": true,
"messages": {
"en-US": {
},
"zh-CN": {
}
}
}
from bundle-tools.
I'll setup a proper reproduction repo for it. Give me a second :)
from bundle-tools.
@kazupon The reproduction is at https://github.com/Tanimodori/unplugin-vue-i18n-regression-repro
from bundle-tools.
The example of @cexbrayat is also causing the error:
import { createI18n } from "vue-i18n";
const en = {};
const i18n = createI18n({
locale: "en",
messages: {
en,
},
});
export default i18n;
export default {
}{
"locale": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["en"])};fn.source="en";return fn;})(),
"messages": {
}
}
from bundle-tools.
So this is the limitation mentioned at https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#include
⚠️ NOTE:js
andts
resources are limited to simple export (export default
) as locale messages object only, such as programmatically dynamic resource construction is not guaranteed to work currently.
v0.8.2 happens to be working and 0.9.1 doesn't.
I'll remove the include
in my config since I don't use pre-compile. Thanks for your quick help!
from bundle-tools.
Related Issues (20)
- failed to load config vite.config.js HOT 1
- TS error unplugin-vue-i18n 0.12.3 in createI18n HOT 2
- Cannot read properties of undefined (reading 'length') HOT 3
- Improper parsing of linked messages with `-` after 0.12 HOT 2
- @intlify/unplugin-vue-i18n doesn't work with Nuxt 3.7 HOT 1
- Missing dependencies and missing MessageFunctionInternal definition HOT 1
- can not inclue js locale files HOT 2
- Changelog of unplugin-vue-i18n is not up to date HOT 3
- @intlify/unplugin-vue-i18n not support HMR with Static bundle importing HOT 1
- Dependency Dashboard
- Module parse failed: Unexpected token (1:0) when combined with html-webpack-plugin HOT 14
- Failed locale loading: Unexpected token 'const'. HOT 1
- Rollup 4 support HOT 1
- `onlyLocales` not working for SFC <i18n locale="xx">
- it is not installed using npm install HOT 1
- Webpack build does not work together with html-webpack-plugin HOT 2
- Using HTML in SFC results in parsing issue `Unexpected scalar at node end` HOT 2
- nuxt3国际化报错 HOT 1
- Missing compile function in SSR build
- Is it possible to make a linkage with i18n Ally HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bundle-tools.