[tsdx-config] Css module build fail
See original GitHub issueHi guys, I just installed tsdx to try out the new functionality of the config file. The step I followed are:
- in the root of the project I created a file called
tsdx.config.js
:
const postcss = require('rollup-plugin-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
module.exports = {
rollup(config, options) {
config.plugins.push(
postcss({
plugins: [
autoprefixer(),
cssnano({
preset: 'default',
}),
],
inject: false,
// only write out CSS for the first bundle (avoids pointless extra files):
extract: !!options.writeMeta,
modules: true,
})
);
return config;
},
};
- I installed the 3 dependencies that are required;
- in the src folder I create a file called:
style.module.css
- in the
index.tsx
I imported it:
import * as React from 'react';
import * as style './style.module.css';
// Delete me
export const Thing = () => {
return (
<div className={style.test}>the snozzberries taste like snozzberries</div>
);
};
- running
yarn start
✖ Failed to compile
(typescript) Error: /Users/daniele/Desktop/testLibTsDx/src/index.tsx(2,19): syntax error TS1005: 'from' expected.
Error: /Users/daniele/Desktop/testLibTsDx/src/index.tsx(2,19): syntax error TS1005: 'from' expected.
at error (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup/dist/rollup.js:9429:30)
at throwPluginError (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup/dist/rollup.js:15701:12)
at Object.error (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup/dist/rollup.js:15756:24)
at Object.error (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup/dist/rollup.js:16148:38)
at RollupContext.error (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:17187:30)
at lodash_3 (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:24954:23)
at arrayEach (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:532:11)
at forEach (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:9360:14)
at printDiagnostics (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:24927:5)
at Object.transform (/Users/daniele/Desktop/testLibTsDx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:26754:17)
✨ Done in 2.18s.
Did I miss something?
Issue Analytics
- State:
- Created 4 years ago
- Comments:29 (4 by maintainers)
Top Results From Across the Web
Customization - TSDX
Build production ready TypeScript packages. The world's leading companies use TSDX to build and test TypeScript packages.
Read more >CSS Module gets bundled but is not referenced using TSDX ...
This causes my styles to not show up at all. Here's my complete tsdx.config.js : const postcss = require('rollup-plugin-postcss ...
Read more >How to use CSS Modules with TypeScript and webpack
You'll get an error: “Cannot find module './Button.css'”. There are several ways to fix that. The easy way. You can bypass TypeScript import...
Read more >How to import CSS and style TSX React components
In this video I'll show you how to make your React application more reliable. Your components and class names will always be consistent....
Read more >Rollup Config for React Component Library With TypeScript + ...
I am just sharing the current Rollup configurations that I use to build my own ... '@rollup/plugin-typescript'; import postcss from "rollup-plugin-postcss"; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For all the people are struggling to add css modules to tsdx this is the solution:
@jaredpalmer feel free to close it or set as fixed or I can create a PR to your readme to add is an example. Up to you and thanks again for the great work!
Hi, I am facing the same problem. I need a .css file in my project and I am trying to import it but I am continuously getting the same error. I tried the code given by @daniele-zurico and I am still facing the same problem.
Any help would be appreciated. Thanks.