1.在这个错误信息中,“Could not find a declaration file for module ‘./App.vue’”一般表示缺少Vue组件的类型声明文件。
要解决这个问题,可以尝试以下两种方法:
- 添加Vue组件类型声明文件。您可以在项目根目录下创建一个名为“vue-shim.d.ts”(如果您没有创建类型声明文件的话),并添加以下内容:
declare module '*.vue' {
import { ComponentOptions } from 'vue'
const componentOptions: ComponentOptions
export default componentOptions
}
**
这将告诉TypeScript如何处理.vue组件文件。请注意,您需要安装@vue/runtime-core包。
我的建议是:
<script setup lang="ts"> </script>即可
2,设置自定义分割代码:
chunkFileNames: 'static/js/[name]-[hash].js', entryFileNames: 'static/js/[name]-[hash].js', assetFileNames: 'static/[ext]/[name]-[hash][extname]', manualChunks(id) { if (id.includes('element-plus')) { return 'element-plus'; } }
3.module.exports = router ts文件显示module错误:、
原因是因为自己设置的module规范不同。
TypeScript 配置文件 tsconfig.json 中设置 module 选项值为 commonjs,以使用 CommonJS 模块系统,或者将您的模块系统语法调整为与您的 TypeScript 配置兼容
"module": "CommonJS",
如果还是不行:
Cannot find name 'module'. Do you need to install type definitions for node? Try npm i --save-dev @types/node.ts
安装:
npm i --save-dev @types/node