目录

Vue3中使用vue-i18n,在typescript v5中编译无法通过的修复方法

目录

最近在做一个小的网站项目,需要实现i18n。

网站截图

网站截图

项目package.json中的内容如下:

  "dependencies": {
    "intl": "^1.2.5",
    "luxon": "^3.4.0",
    "pinia": "^2.1.6",
    "vue": "^3.3.4",
    "vue-i18n": "^9.2.2",
    "vue-router": "^4.2.4"
  },
  "devDependencies": {
    "@intlify/unplugin-vue-i18n": "^0.12.3",
    "@rushstack/eslint-patch": "^1.3.2",
    "@tsconfig/node18": "^18.2.0",
    "@types/jsdom": "^21.1.1",
    "@types/luxon": "^3.3.1",
    "@types/node": "^18.17.0",
    "@vicons/ionicons5": "^0.12.0",
    "@vitejs/plugin-vue": "^4.2.3",
    "@vitejs/plugin-vue-jsx": "^3.0.1",
    "@vue/eslint-config-prettier": "^8.0.0",
    "@vue/eslint-config-typescript": "^11.0.3",
    "@vue/test-utils": "^2.4.1",
    "@vue/tsconfig": "^0.4.0",
    "cypress": "^12.17.2",
    "eslint": "^8.45.0",
    "eslint-plugin-cypress": "^2.13.3",
    "eslint-plugin-vue": "^9.15.1",
    "jsdom": "^22.1.0",
    "naive-ui": "^2.34.4",
    "npm-run-all": "^4.1.5",
    "prettier": "^3.0.0",
    "start-server-and-test": "^2.0.0",
    "typescript": "~5.1.6",
    "unplugin-auto-import": "^0.16.6",
    "unplugin-vue-components": "^0.25.1",
    "vfonts": "^0.0.3",
    "vite": "^4.4.6",
    "vitest": "^0.33.0",
    "vue-tsc": "^1.8.6"
  }

由于typescript使用版本为5.0以上,当项目完成使用 npm run build 编译打包时,却遇到了warning导致编译无法通过。

编译时返回的错误信息,如下:

There are types at 'node_modules/vue-i18n/dist/vue-i18n.d.ts', but this result could not be resolved when respecting package.json "exports". The 'vue-i18n' library may need to update its package.json or typings.

在Google上搜索许久,终于在Github上vue-i18n的issues中找到了解决方法。

issuses的链接地址:https://github.com/intlify/vue-i18n-next/issues/1327

其中有效的解决方法

issues中的解决方法

issues中的解决方法