intlify / intlify/bundle-tools

Cannot import message files as `?raw` or `?url` in Vite

Open
#505 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
270
Forks
46
PR merge metrics
No merged PRs in 30d

Description

### Reporting a bug?

For use in a translation tool, I need to import the message files as strings without preprocessing, however this plugin tries to interpret the generated `export default ...` statement as JSON/YAML/etc.

### Expected behavior

As the Vite docs would suggest, it should just import the file contents as a string without any errors.

### Reproduction

```ts
const messages: Record = import.meta.glob("./*.yaml", {
eager: true,
base: "./locales",
query: "?raw",
import: "default",
});
```

```ts
// https://vite.dev/config/
export default defineConfig({
plugins: [vue(), vueDevTools(), vueI18n({ include: "src/locales/**" }), tailwindcss()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});
```

The resulting error:

```
4:50:15 PM [vite] Internal server error: Nested mappings are not allowed in compact mappings
Plugin: unplugin-vue-i18n:resource
File: /Users/j.pritzkau/dev/playground/vue-i18n/src/locales/jp.yaml?raw
at Context.throwError (/Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/yaml-eslint-parser@1.3.0/node_modules/yaml-eslint-parser/lib/context.js:77:15)
at processDoc (/Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/yaml-eslint-parser@1.3.0/node_modules/yaml-eslint-parser/lib/yaml-cst-parse.js:16:23)
at parseAllDocsToCST (/Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/yaml-eslint-parser@1.3.0/node_modules/yaml-eslint-parser/lib/yaml-cst-parse.js:31:9)
at parseForESLint (/Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/yaml-eslint-parser@1.3.0/node_modules/yaml-eslint-parser/lib/parser.js:13:57)
at parseYAML (/Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/yaml-eslint-parser@1.3.0/node_modules/yaml-eslint-parser/lib/index.js:57:40)
at generate (file:///Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/@intlify+bundle-utils@11.0.0_petite-vue-i18n@11.1.12_vue@3.5.21_typescript@5.8.3___vue-_16c0f19ce239c6c38c52816c476bcccc/node_modules/@intlify/bundle-utils/lib/index.mjs:853:13)
at TransformPluginContext.handler (file:///Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/@intlify+unplugin-vue-i18n@11.0.0_@vue+compiler-dom@3.5.21_eslint@9.35.0_jiti@2.5.1__pe_5bf3e43d53489ca6742509fc90208fd7/node_modules/@intlify/unplugin-vue-i18n/lib/index.mjs:438:54)
at async file:///Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/vite-plugin-inspect@11.3.3_vite@7.1.4_@types+node@22.18.1_jiti@2.5.1_lightningcss@1.30.1_yaml@2.8.1_/node_modules/vite-plugin-inspect/dist/shared/vite-plugin-inspect.BzUKaD4x.mjs:403:17
at async EnvironmentPluginContainer.transform (file:///Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/vite@7.1.4_@types+node@22.18.1_jiti@2.5.1_lightningcss@1.30.1_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-C6pp_iVS.js:31320:14)
at async loadAndTransform (file:///Users/j.pritzkau/dev/playground/vue-i18n/node_modules/.pnpm/vite@7.1.4_@types+node@22.18.1_jiti@2.5.1_lightningcss@1.30.1_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-C6pp_iVS.js:26407:26)
```

### Issue Package

unplugin-vue-i18n

### System Info

```shell
System:
OS: macOS 15.5
CPU: (8) arm64 Apple M2
Memory: 200.25 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.3.0 - ~/.nvm/versions/node/v24.3.0/bin/node
npm: 11.4.2 - ~/.nvm/versions/node/v24.3.0/bin/npm
pnpm: 10.15.1 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 139.0.7258.155
Safari: 18.5
npmPackages:
vite: ^7.0.6 => 7.1.4
vue: ^3.5.18 => 3.5.21
vue-i18n: ^11.1.12 => 11.1.12
```

### Screenshot

_No response_

### Additional context

_No response_

### Validations

- [x] Read the [Contributing Guidelines](https://github.com/intlify/bundle-tools/blob/main/CONTRIBUTING.md).
- [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](https://github.com/intlify/bundle-tools/discussions).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.