intlify / vue-i18n-loader

:globe_with_meridians: vue-i18n loader for custom blocks
MIT License
267 stars 29 forks source link

Failed to load .yaml using webpack (filetype not detected) #175

Closed last-partizan closed 3 years ago

last-partizan commented 3 years ago

I'm trying to import yml file using vue-i18n-loader, but it tries to load it like json, and fails.

I'm using webpack-4, with following config from readme:

        {
          test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
          type: "javascript/auto",
          loader: "@intlify/vue-i18n-loader",
          include: [ // Use `Rule.include` to specify the files of locale messages to be pre-compiled
            path.resolve(__dirname, "locale"),
          ],
        },

When i try to import yml file, like this:

import ru from "@locale/ru/example.yml";

If fails with following message:

SyntaxError: Unexpected token i in JSON at position 1
    at JSON.parse (<anonymous>)
    at generateCode (/home/serg/Projects/example/node_modules/@intlify/vue-i18n-loader/lib/index.js:29:22)
    at Object.loader (/home/serg/Projects/example/node_modules/@intlify/vue-i18n-loader/lib/index.js:13:55)

I used debugger to figure out what is happening, and problem is in this.resourceQuery, it's empty string. So yml is treatead as json.

Here is minimal reproduction: https://github.com/last-partizan/vue-i18n-loader-bug

Is there error in my configuration, or is this really a bug?

kazupon commented 3 years ago

Thank you for your reporting!

For Vue I18n v9, You need to use @intlify/vue-i18n-loader@next. https://github.com/intlify/vue-i18n-loader#cd-installation

Could you re-try about it?

last-partizan commented 3 years ago

@kazupon yes, it works with @next version.

Is v9 compatible with vue-2?

For now i just used yaml-loader to import this file, but if Vue I18n v9 is compatible with vue-2, i'll try to upgrade.

kazupon commented 3 years ago

Vue I18n v9 has several breaking changes to support Vue 3, but other than that, the I/F keep almost compatible. You can check about breaking change. https://vue-i18n.intlify.dev/guide/migration/breaking.html#apis

last-partizan commented 3 years ago

Thank you.