I am trying to add images using import
import image from '../assets/images/picture.jpg
am using Typescript with gatsby ... the strange thing is it works fine with normal javascript (.js ~ .jsx file) but when I use (.ts ~ .tsx file) it throw out this error
Cannot find module '../assets/images/picture.jpg' or its corresponding type declarations.ts(2307)
The strange thing is it works fine with normal components like
import Header from '../components/Header'
here is my tsconfig.json file
{
"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/**/*"
]
}
and here is gatsby-config.json file
module.exports = {
/* Your site config here */
plugins: [
{
resolve: `gatsby-plugin-typescript`,
options: {
isTSX: true, // defaults to false
jsxPragma: `jsx`, // defaults to "React"
allExtensions: true, // defaults to false
},
},
],
}
folder Structure
- src
- components
- MainComponent.tsx
- Header.tsx
- assets
- images
- picture.jpg
- images
- components