Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code will not build when using CSS Modules + TypeScript #822

Closed
nickrttn opened this issue Mar 27, 2021 · 5 comments
Closed

Code will not build when using CSS Modules + TypeScript #822

nickrttn opened this issue Mar 27, 2021 · 5 comments

Comments

@nickrttn
Copy link

Summary

I'm trying to bundle a React component library. I'm using Typescript and CSS Modules. When I try to build (or watch for that matter), I receive the error:

(rpt2 plugin) Error: ..../project/src/component.tsx(1,20): semantic error TS2307: Cannot find module './component.module.css' or its corresponding type declarations.

I can reproduce this in a reduced test case: https://github.com/nickrttn/microbundle-ts-css-modules

With the types added in the test case as documented in #740 I would have expected this to build. I've also tried to add https://github.com/mrmckeb/typescript-plugin-css-modules instead, with the same results. Strangely, VS Code does pick up on both of these changes.

Expected result

yarn build should work. I've taken the custom tsconfig.json and types from #740.

Actual result

This error during building or watching:

(rpt2 plugin) Error: ..../project/src/component.tsx(1,20): semantic error TS2307: Cannot find module './component.module.css' or its corresponding type declarations.
@rschristian
Copy link
Collaborator

rschristian commented Mar 28, 2021

Your issue is with this line: https://github.com/nickrttn/microbundle-ts-css-modules/blob/232190ee2f4e9cf80c5ec60aae9d92fae70c821b/package.json#L10

The bad path breaks things. Simply correct it to dist/index.d.ts and it'll build fine.

Need to look into it a bit further to figure out why it breaks in this fashion, but correcting that will get things working again for you.

@nickrttn
Copy link
Author

Yep, that is a strange error in response to that typo. Just removing the key completely fixes it as well.

I did expect not to have to add the types manually after the fix for #740 was merged, but that seems to be due to the ambient types not being included on npm?

@rschristian
Copy link
Collaborator

Yeah, I'll get that fixed.

@rschristian
Copy link
Collaborator

Just had #823 merged in, should ensure those types are accessible to end users.

As for the error message, I believe that's upstream in rollup-plugin-typescript2, though what you wrote would be an error when using tsc all the same. We extrapolate the declaration dir from your types, which in this case would be the project root. That seems to break tsc, which in turn, I'm guessing, throws off rpt2. Not entirely sure why TSC can't handle that, but it can't.

@rschristian
Copy link
Collaborator

Closing as the path is invalid in other environments, so this isn't a Microbundle issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants