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

When postcss modules are present, in some scenarios react-docgen tries to parse css files #892

Open
larowlan opened this issue Jan 21, 2024 · 2 comments

Comments

@larowlan
Copy link

Background

In certain scenarios react-docgen tries to parse CSS modules.

This yields an error as follows:

Use case

See related Storybook issue storybookjs/storybook#25662 and stackblitz reproduction https://stackblitz.com/edit/github-cwovgn-yvzreq

Have a component like so

import React from "react"
import styles, { stylesheet } from "./Container.module.css"

const Container = ({ children }) => (
  <div>
    {children}
  </div>
)

export default Container;
export stylesheet;

And where the css file contains an @import

@import url("../../css/variables.css");

The babel config passed to react-docgen doesn't take into account the .babelrc file and attempts to parse the .css file as JavaScript.

This causes an error like so

[vite] Internal server error: /path/to/Container.module.css: Support for the experimental syntax 'decorators' isn't currently enabled (1:1):

Is there anyway to configure react-docgen to ignore .css files in this case?

If you're wondering why are we importing and exporting the processed stylesheet, we're building a critical css component that inlines CSS needed for the first paint. We're doing this by using rollup-post-css-modules to import postcss modules but also export the built stylesheet so it can be collated in a reliable fashion (ie the class names don't change from what is rendered in the component).

@larowlan larowlan changed the title Bug: When postcss modules are present, in some scenarios react-docgen tries to parse css files When postcss modules are present, in some scenarios react-docgen tries to parse css files Jan 21, 2024
@larowlan
Copy link
Author

Removed the 'bug' prefix, because this might be a configuration issue in Storybook

@thenoiro
Copy link

Have the same bug. Strange, but it disappears when I import style variables right in that place I need to use, instead of re-exporting from another file.

Syntax error:
bug

No error:
nobug

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