Solid: src/App.tsx:1:18 - error TS2307: Cannot find module './logo.svg'.

Created on 21 Apr 2020  路  4Comments  路  Source: ryansolid/solid

When I run:

npm init solid app-ts my-solidjs-app-ts
cd my-solidjs-app-ts
npm run check-types

I get the TypeScript compile error:

src/App.tsx:1:18 - error TS2307: Cannot find module './logo.svg'.

"npm start" works fine.

bug

Most helpful comment

@ryansolid Wow, this was the fastest github-issue-creation-to-bugfix experience I had ever. Thank you!

All 4 comments

@shybyte

In the src directory create a file assets.d.ts or whatever name you would like, and add in:

declare module "*.svg" {
  const content: any;
  export default content;
}

Reference: https://webpack.js.org/guides/typescript/#importing-other-assets

Thanks @s0kil . I can't believe I missed that. I like remember doing that. But maybe it was in a different project. But I don't remember having any build errors,... but that's probably because of babel. Ok yeah I probably should have that in there. Although weirdly it's not there in the source (this is lifted from Create React).. https://github.com/facebook/create-react-app/tree/master/packages/cra-template-typescript/template. Very strange.

@shybyte I will look into this (and this reminds me, update the Solid logo). Sorry for any inconvenience.

I found that react was packing a global typedef for this stuff but I was having some issues getting this working without messing with the tsconfig (even then I couldn't just add to typeRoots). So while this appears fixed it isn't just a matter of updating the scripts project. It's probably easiest to just redo it fresh. Alternatively do as @s0kil suggested. New installations should work now at least. I've done a fresh install myself to check.

Thank you so much for bringing this to my attention. And let me know if you have any other issues.

@ryansolid Wow, this was the fastest github-issue-creation-to-bugfix experience I had ever. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trusktr picture trusktr  路  5Comments

trusktr picture trusktr  路  3Comments

Ziriax picture Ziriax  路  4Comments

aguilera51284 picture aguilera51284  路  7Comments

tehdarthvid picture tehdarthvid  路  5Comments