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

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

Closed
sergiop opened this issue Oct 25, 2019 · 5 comments
Closed

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

sergiop opened this issue Oct 25, 2019 · 5 comments
Labels
kind: regression topic: v0.10.x Issues related to broken builds in v0.10.x / @wessberg/rollup-plugin-ts

Comments

@sergiop
Copy link

sergiop commented Oct 25, 2019

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
@sergiop
Copy link
Author

sergiop commented Oct 25, 2019

I dug inside the code, and from what I've seen, the issue started when, two weeks ago, @medelman17 added @wessberg/rollup-plugin-ts in place of rollup-plugin-typescript2.

Here the change: bfc0590#diff-85d99c527c01407b9055b07762a4ad45L11

On my computer I just reverted the changes only on that file, and with the old configuration the build passes, but I really have no idea on how to fix using @wessberg/rollup-plugin-ts.

@sergiop
Copy link
Author

sergiop commented Oct 26, 2019

I played a little more and I found that if I use typescript instead of babel as a transpiler in @wessberg/rollup-plugin-ts config, the build passes.

https://github.com/jaredpalmer/tsdx/blob/master/src/createRollupConfig.ts#L146

@sergiop
Copy link
Author

sergiop commented Oct 28, 2019

Last but not least, I found that probably the issue is not strictly related to css-modules or a custom tsdx.config.js but more simply to the import of a CSS file.

Removing tsdx.config.js file and importing a simple css (not a css-module), returns the same build error:

/src/style.css

.test {
  color: red;
}

/src/index.tsx

import * as React from 'react';
import './style.css';

// Delete me
export const Thing = () => {
  return <div className="test">the snozzberries taste like snozzberries</div>;
};

@swyxio
Copy link
Collaborator

swyxio commented Nov 4, 2019

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

@swyxio swyxio closed this as completed Nov 4, 2019
@sergiop
Copy link
Author

sergiop commented Nov 4, 2019

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

@agilgur5 agilgur5 added the topic: v0.10.x Issues related to broken builds in v0.10.x / @wessberg/rollup-plugin-ts label Mar 15, 2020
Repository owner locked as resolved and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: regression topic: v0.10.x Issues related to broken builds in v0.10.x / @wessberg/rollup-plugin-ts
Projects
None yet
Development

No branches or pull requests

3 participants