solidjs / solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.
https://solidjs.com
MIT License
32.05k stars 914 forks source link

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

Closed shybyte closed 4 years ago

shybyte commented 4 years ago

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.

s0kil commented 4 years ago

@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

ryansolid commented 4 years ago

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.

ryansolid commented 4 years ago

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.

shybyte commented 4 years ago

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