我正在尝试使用导入添加图像
import image from '../assets/images/picture.jpg
Run Code Online (Sandbox Code Playgroud)
我正在将 Typescript 与 gatsby 一起使用...奇怪的是它可以与普通的 javascript (.js ~ .jsx 文件)一起使用,但是当我使用(.ts ~ .tsx 文件)时它会抛出此错误
找不到模块“../assets/images/picture.jpg”或其相应的类型声明。TS(2307)
奇怪的是它与普通组件一起工作得很好,比如
import Header from '../components/Header'
Run Code Online (Sandbox Code Playgroud)
这是我的tsconfig.json文件
{
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"jsx": "preserve",
"lib": [
"dom",
"es2015",
"es2017"
],
"strict": true,
"noEmit": true,
"isolatedModules": true,
"esModuleInterop": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false,
"preserveConstEnums": true
},
"include": [
"./src/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
这是gatsby-config.json 文件
module.exports = {
/* …Run Code Online (Sandbox Code Playgroud)