vue3 main.ts文件中引入js文件

提示无法找到模块的申明文件
在这里插入图片描述
解决步骤:

  1. 在tsconfig.json文件中加入一个参数:allowJS
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowJs": true,  //编译时允许有js
    "allowSyntheticDefaultImports": true,  //允许引入没有默认导出的模块
 }
  1. include中加入js
  "include": [
    "src/**/*.ts",
    "src/**/*.js",//添加路径支持js
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],

此时tsconfig.json会出现一个报错

 

 需要在tsconfig.json文件中加入一个新的参数:outDir 即可

    "allowJs": true, //允许有js
    "allowSyntheticDefaultImports": true, //允许引用没有默认导出的模块
    "outDir": "./",  //将输出结构重定向到目录

 

posted @ 2022-10-24 18:28  爵岚  阅读(3055)  评论(0)    收藏  举报