Importing images in TypeScript React - “Cannot find module”

前端 未结 5 1621
南笙
南笙 2020-12-29 01:59

I am trying to import images to use inside a React component with TypeScript. The bundler I\'m using is Parcel (not Webpack).

I have created a .d.ts fil

5条回答
  •  离开以前
    2020-12-29 02:37

    If you literally wrote "include": ["./src/index.d.ts"] in tsconfig.json and you don't have a "files" setting, that means the project defined by tsconfig.json includes only the single file ./src/index.d.ts. When you open any other file in VS Code, VS Code uses a separate language service instance that doesn't use your tsconfig.json. Adjust your "include" setting to match all the .ts and .tsx files in your project, or just delete it and rely on the default behavior of including all files under the directory containing tsconfig.json.

    Round 2

    TypeScript is ignoring index.d.ts because it assumes that index.d.ts is generated from index.tsx and index.tsx is more likely to be up to date. Name your index.d.ts file something else, e.g., declaration.d.ts.

提交回复
热议问题