6

当我尝试 vue add i18n 时,我遇到了这个错误:

      Invoking generator for vue-cli-plugin-i18n...
 ERROR  Error: You cannot call "get" on a collection with no paths. Instead, check the "length" property first to verify at least 1 path exists.
Error: You cannot call "get" on a collection with no paths. Instead, check the "length" property first to verify at least 1 path exists.
    at Collection.get (/usr/local/lib/node_modules/@vue/cli/node_modules/jscodeshift/src/Collection.js:213:13)
    at injectOptions (/usr/local/lib/node_modules/@vue/cli/lib/util/codemods/injectOptions.js:15:6)
    at runTransformation (/usr/local/lib/node_modules/@vue/cli/node_modules/vue-codemod/dist/src/run-transformation.js:61:17)
    at Object.keys.forEach.file (/usr/local/lib/node_modules/@vue/cli/lib/Generator.js:290:23)
    at Array.forEach (<anonymous>)
    at Generator.resolveFiles (/usr/local/lib/node_modules/@vue/cli/lib/Generator.js:276:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)

vue add 命令之前的 package.json 如下所示:

{
  "name": "com.food-cheatsheet",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^3.0.0-0",
    "vue-router": "^4.0.0-0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0-0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.0.0-0",
    "tailwindcss": "^1.7.5"
  }
}

vue create到目前为止,我使用并安装了 tailwindcss 和 postcss 设置了项目。

你能描述一下,这个错误的真正含义是什么?我想它与 i18n 无关,但在我使用时也会与其他模块一起发生add

  • npm install vue-i18n作品(仅供参考)

附加问题

如何在 vuejs 3.0 中设置 i18n?vuejs2 和 3 的区别在哪里?

4

1 回答 1

1

vuetifyjs 同样的问题https://github.com/vuetifyjs/vue-cli-plugins/issues/140

对于 Vue 3

npm install --save vue-i18n@next
yarn add vue-i18n@next

并手动配置 i18n

来自 vue-i18n-next 的示例:

使用可组合 API 的示例

使用旧版 API 的示例

示例目录

如果你想安装vue add i18n更改

createApp(App)
  .use(store)
  .use(router)
  .mount("#app");

  new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount("#app");

对于打字稿项目添加 vue-i18n.d.ts 文件,内容为

declare module "vue-i18n"

对于 vue 3,我安装npm install --save vue-i18n@next而不是vue add i18n

于 2020-10-09T15:21:30.060 回答