常见问题警告与报错
2025/2/26小于 1 分钟
报错
报错:Module "path" has been externalized for brower compatibility and cannot be accesed in client code
- 安装依赖
npm install path-browserify- 使用
path-browserify代替path模块
import path from 'path-browserify'::: 无法找到模块“@/components/xxx.vue”的声明文件, 隐式拥有 "any" 类型
根目录新建文件
env.d.ts文件,并加入以下代码
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}:::
警告
Vite 项目中 vue-i18n 依赖警告问题:vue-i18n.esm-bundler.js:39 You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
// 在 vite.config.js alias 中加入下面配置
export default defineConfig({
resolve: {
alias: {
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
}
}
})