bundle-tools icon indicating copy to clipboard operation
bundle-tools copied to clipboard

Unexpected token error after 0.9.0 @intlify/unplugin-vue-i18n

Open MinatoHikari opened this issue 2 years ago • 3 comments

Reporting a bug?

when I use function like

pagination: {
    pages: ({ named }: Parameters<MessageFunction>[0]) => `${named('number')}/page`,
    total: ({ named }: Parameters<MessageFunction>[0]) => `${named('number')} records in total`,
},
confirm: {
    confirm_deletion: 'confirm deletion?',
    confirm_void: 'confirm void?',
    confirm_release: 'confirm release?',
    ack: 'ack',
    cancel: 'cancel',
    non_records: 'Please choose at least one record',
},

I get an error when run vite build:

Unexpected token (Note that you need plugins to import files that are not JavaScript)
file: /xxx/locales/en-US.ts:116:3
114:   "pagination": {
115:     
116:   }"confirm": {
        ^
117:     "confirm_deletion": (ctx) => {const { normalize: _normalize } = ctx;return _normalize(["confirm deletion?"])},
118:     "confirm_void": (ctx) => {const { normalize: _normalize } = ctx;return _normalize(["confirm void?"])},
error during build:
RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:2105:30)
    at Module.error (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:13174:16)
    at Module.tryParse (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:13851:25)
    at Module.setSource (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:13461:39)
    at ModuleLoader.addModuleSource (file:///xxx/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:23422:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
 ELIFECYCLE  Command failed with exit code 1.

Expected behavior

Every thing works well in 0.8.2 with same resource above.

Reproduction

https://github.com/MinatoHikari/unplugin-i18n-bug

pnpm i
pnpm run build

Process will end with an error.

Change @intlify/unplugin-vue-i18n version to 0.8.2.

pnpm i
pnpm run build

Every thing works well.

Issue Package

unplugin-vue-i18n

System Info

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 198.56 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/.volta/tools/image/node/18.15.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 9.5.0 - ~/.volta/tools/image/node/18.15.0/bin/npm
  Browsers:
    Chrome: 111.0.5563.64
    Chrome Canary: 113.0.5667.3
    Firefox Developer Edition: 112.0
    Safari: 16.3
  npmPackages:
    rollup: 3.18.0 => 3.18.0 
    vite: ^4.2.1 => 4.2.1 
    vue: ^3.2.47 => 3.2.47 
    vue-i18n: ^9.2.2 => 9.2.2

Screenshot

No response

Additional context

No response

Validations

  • [X] Read the Contributing Guidelines.
  • [X] Read the README
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion.

MinatoHikari avatar Mar 22 '23 05:03 MinatoHikari

Thank you for your reporting!

Ah… I’ve forgot for the case where the message functions were directly in the locale 😅 I'll fix this issue.

kazupon avatar Mar 22 '23 05:03 kazupon

Thank you for your reporting!

Ah… I’ve forgot for the case where the message functions were directly in the locale 😅 I'll fix this issue.

hello, ite seems that you also forgot the import of ts files.

import homepage from './pages/homepage/index';
homepage: {
       homepage: homepage.homepage.zhCN,
 },

MinatoHikari avatar Apr 28 '23 06:04 MinatoHikari

@kazupon

MinatoHikari avatar Apr 28 '23 06:04 MinatoHikari