相关疑难解决方法(0)

找不到模块“file-name.png”或其相应的类型声明 - Typescript React

我正在尝试在我的打字稿反应项目中导入一个 png,如下所示:
import logo from 'assets/Logo.svg';

我收到了这个 TS 错误:
Cannot find module 'assets/Logo.svg' or its corresponding type declarations.ts(2307)

知道这是为什么吗?我已tsconfig.json在下面附加了我的文件,以防我配置不正确:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "baseUrl": "src"
  },
  "include": ["src"]
} 
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

38
推荐指数
1
解决办法
4万
查看次数

标签 统计

reactjs ×1

typescript ×1