intlify / bundle-tools

bundling for intlify i18n tools
MIT License
232 stars 37 forks source link

vite:eslint throws error with messages #2

Open bokuns opened 3 years ago

bokuns commented 3 years ago

I add eslintPlugin() in vite.config.js as following:

export default defineConfig({
    plugins: [
        vue(),
        eslintPlugin({
            fix: true,
            exclude: path.resolve(__dirname, './src/main.js'), // still throw the error even I excluded main.js from here
        }),
        vueI18n({
            include: path.resolve(__dirname, './src/i18n/**'),
        }),
    ],
});

and it throws an error:

[vite] Internal server error: No files matching '@intlify/vite-plugin-vue-i18n/messages' were found.
Plugin: vite:eslint
File: @intlify/vite-plugin-vue-i18n/messages

Here's my main.js:

import { createApp } from 'vue';
import { createI18n } from 'vue-i18n';
import messages from '@intlify/vite-plugin-vue-i18n/messages';
import App from './App.vue';

const i18n = createI18n({
    messages,
});

createApp(App).use(i18n).mount('#app');

Note: Removing eslintPlugin() from vite.config.js would get rid of the error, but I do want to keep EsLint functionality though...

I'm not sure this is caused by vite-plugin-eslint or vite-plugin-vue-i18n. Let me know if I should turn it to vite-plugin-eslint instead.

Versions:

imShara commented 2 years ago

Same here with vite-ssr plugin

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "useDefineForClassFields": true,
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": [
      "esnext",
      "dom"
    ],
    "types": ["@intlify/vite-plugin-vue-i18n/client"]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "src/**/*.tsx",
    "src/**/*.vue"
  ]
}

main.ts

import { createI18n } from 'vue-i18n'
import messages from '@intlify/vite-plugin-vue-i18n/messages'

const i18n = createI18n({
  locale: 'en',
  fallbackLocale: 'en',
  messages,
  legacy: false,
})
app.use(i18n)

pnpm vite-ssr

[vite] Error when evaluating SSR module …/src/main.ts:
Error: Cannot find module '@intlify/vite-plugin-vue-i18n/messages' from '…/src'

Looks like it tried to find virtual module in source dir.

userquin commented 2 years ago

also failing on vite-ssg: ./messages subpkg missing on package exports entry

EDIT: with latest vite plugin, 3.3.1

mitow7821 commented 2 years ago

I think thats related (eslint error): Resolve error: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './messages' is not defined by "exports" in \node_modules\@intlify\vite-plugin-vue-i18n\package.json

productdevbook commented 2 years ago

Cannot find module '@intlify/vite-plugin-vue-i18n/messages' or its corresponding type declarations.ts(2307)

imShara commented 2 years ago

Use this instead for SSG/SSR

const messages = Object.fromEntries(
  Object.entries(import.meta.globEager("../locales/*.yaml")).map(
    ([key, value]) => [key.slice(11, -5), value.default]
  )
);
trylovetom commented 1 year ago

Just ignore it

eslintrc.json

{
  "settings": {
    "import/core-modules": [
      "@intlify/vite-plugin-vue-i18n/messages",
      ...
    ]
  },
  ...
}