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

  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",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],

此时tsconfig.json会出现一个报错
在这里插入图片描述
需要加入一个新的参数:outDir 即可

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

鸿蒙生态一站式服务平台。

更多推荐