question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding css-modules with a custom Rollup config breaks the build.

See original GitHub issue

Current Behavior

Create a new project with react template: npx tsdx create mylib

  1. Add postcss plugin and extend Rollup config with tsdx.config.js
yarn add -D rollup-plugin-postcss
const postcss = require('rollup-plugin-postcss');
module.exports = {
  rollup(config, options) {
    config.plugins.push(
      postcss({
        modules: true,
      })
    );
    return config;
  },
};
  1. Add a test css-module file /src/style.module.css, import and use it in /src/index.tsx
.test {
  color: red;
}
import * as React from 'react';
import styles from './style.module.css';

// Delete me
export const Thing = () => {
  return <div className={styles.test}>the snozzberries taste like snozzberries</div>;
};
  1. Build the library
yarn build

The build script exits with this error:

sergiopedercini_MBP-di-Sergio____Dev_mylib__zsh_

Suggested solution(s)

Apparently, the custom configuration added in tsdx.config.js is not interpreted and the parser doesn’t seem to know how to manage the .test css class in style.module.css.

If you downgrade TSDX to 0.9.3 the build passes.

This issue happens with TSDX >= v0.10.0

Your environment

Software Version(s)
TSDX 0.10.5
TypeScript 3.6.4
Yarn 1.19.0
Node v10.15.3
Operating System macOS 10.14.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
sw-yxcommented, Nov 4, 2019

do you mind retrying with v0.11? we reverted the change to @wessberg/rollup-plugin-ts. reopen if still persists.

0reactions
sergiopcommented, Nov 4, 2019

I can confirm @sw-yx, upgrading to v0.11 solves the issue. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to setup rollup for css modules in TypeScript
I found about a preserveModules flag for the rollup config file from ... import babel from 'rollup-plugin-babel'; import typescript from ...
Read more >
How to Bundle JavaScript With Rollup — Step-by- ...
Learn how to use Rollup as a smaller, more efficient alternative to webpack and Browserify to bundle JavaScript files in this step-by-step tutorial...
Read more >
rollup.js
Rollup should typically be used from the command line. ... Import a specific item from a source module, with a custom name assigned...
Read more >
rollup-plugin-postcss
Start using rollup-plugin-postcss in your project by running `npm i ... rollup.config.js ... Or with custom options for `postcss-modules`.
Read more >
Creating a React Component Library using Rollup, Typescript ...
This will generate and place the types of our components within our build folder. Feel free to adjust this config to your liking....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found