wmr: Typescript error for css module imports
Using the default demo template, I get the following error in any index.js
file when importing from css (modules):
Cannot find module './style.module.css' or its corresponding type declarations.
I recommend using a d.ts file for common non-js imports like CRA does: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/lib/react-app.d.ts
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 16 (8 by maintainers)
@Paratron try adding this to your
tsconfig.json
:I just wanted to note that I created a new WMR project with
npm init wmp whatever
a couple of minutes ago and I have the exact same error in the provided example code:Yeah, we noticed that yesterday and this was fixed with #256
I was going to open a PR but it seems the code on master will fix this issue.
I think the issue @ivancuric and I are seeing is related with the order ambient modules are declared. This is the order I’m getting with wmr@1.0.0 :
But on master the order is correct. (which is a bummer, I was eager to make a splash with an easy fix PR )
@Paratron Unfortunately that’s an issue with the way JetBrains handles types. I raised the issue a few months back, but they have no interest in fixing it. I ended up switching away from their products shortly after. You can add a dummy
import 'wmr';
to say yourindex.js
to remove the error.Edit: I shouldn’t say they have no interest in fixing it. They argue that types from a package that is not used should not be used. As WMR is a build tool, it is not directly imported, ergo, JB says the types it provides shouldn’t be used. I’m not entirely sure if I agree or not, as I can see the logic either way, but that’s their position and it’s at odds with what we currently do here.
Ah thanks for clarifying that @Marabyte, I hadn’t realized it was because of the peerDependencies thing.
preact-iso
is correct in that regard, we just needed to havecreate-wmr
do the right thing as @rschristian mentioned.We’ll get a release out today that sorts these things out.
Ok, I had
"typescript.disableAutomaticTypeAcquisition": true,
enabled in VScode for some reason. Removed it.Now two projects using
create-wmr
are reporting different errors. A newly created one can’t seem to get typings forpreact/hooks
and there are errors when accessing CSS modules:Could be a VScode / TS quirk.
There is a
tsconfig.json
but it was generated usingcreate-wmr
.What’s interesting is that I don’t seem to have any typing available. Everything is either inferred return types or
any
.Eg
About
is inferred as:The only thing that seems to be typed is
useState
frompreact/hooks
:I’m using VScode 1.52 if it helps.