Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3636b3

Browse files
benmvpgajus
authored andcommitted
Add error FAQs (#283)
1 parent 59e05a2 commit e3636b3

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

‎README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ NODE_ENV=production ./test
163163
## How does it work?
164164

165165
1. Builds index of all stylesheet imports per file (imports of files with `.css` or `.scss` extension).
166-
1. Uses [postcss](https://github.com/postcss/postcss) to parse the matching CSS files.
166+
1. Uses [postcss](https://github.com/postcss/postcss) to parse the matching CSS files into a lookup of CSS module references.
167167
1. Iterates through all [JSX](https://facebook.github.io/react/docs/jsx-in-depth.html) element declarations.
168168
1. Parses the `styleName` attribute value into anonymous and named CSS module references.
169169
1. Finds the CSS class name matching the CSS module reference:
@@ -239,7 +239,7 @@ To add support for different CSS syntaxes (e.g. SCSS), perform the following two
239239
npm install postcss-scss --save-dev
240240
```
241241

242-
2. Add a filetype syntax mapping to the Babel plugin configuration
242+
2. Add a `filetypes` syntax mapping to the Babel plugin configuration. For example for SCSS:
243243

244244
```json
245245
"filetypes": {
@@ -249,7 +249,7 @@ To add support for different CSS syntaxes (e.g. SCSS), perform the following two
249249
}
250250
```
251251

252-
And optionaly specify extra plugins
252+
And optionally specify extra plugins:
253253

254254
```json
255255
"filetypes": {
@@ -262,7 +262,9 @@ To add support for different CSS syntaxes (e.g. SCSS), perform the following two
262262
}
263263
```
264264

265-
Postcss plugins can have options specified by wrapping the name and an options object in an array inside your config
265+
> NOTE: [`postcss-nested`](https://github.com/postcss/postcss-nested) is added as an extra plugin for demonstration purposes only. It's not needed with [`postcss-scss`](https://github.com/postcss/postcss-scss) because SCSS already supports nesting.
266+
267+
Postcss plugins can have options specified by wrapping the name and an options object in an array inside your config:
266268

267269
```json
268270
"plugins": [
@@ -490,3 +492,32 @@ To enable live reloading of the CSS:
490492
> Note:
491493
>
492494
> This is a [webpack](https://webpack.github.io/) specific option. If you are using `babel-plugin-react-css-modules` in a different setup and require CSS live reloading, raise an issue describing your setup.
495+
496+
### I get a "Cannot use styleName attribute for style name '`[X]`' without importing at least one stylesheet." error
497+
498+
First, ensure that you are correctly importing the CSS file following the [conventions](#conventions).
499+
500+
If you are correctly importing but using different CSS (such as SCSS), this is likely happening because your CSS file wasn't able to be successfully parsed. You need to [configure a syntax loader](#configurate-syntax-loaders).
501+
502+
### I get a "Could not resolve the styleName '`[X]`' error but the class exists in the CSS included in the browser.
503+
504+
First, verify that the CSS is being included in the browser. Remove from `styleName` the reference to the CSS class that's failing and view the page. Search through the `<style>` tags that have been added to the `<head>` and find the one related to your CSS module. Copy the code into your editor and search for the class name.
505+
506+
Once you've verified that the class is being rendered in CSS, the likely cause is that the `babel-plugin-react-css-modules` is unable to find your CSS class in the parsed code. If you're using different CSS (such as SCSS), verify that you have [configured a syntax loader](#configurate-syntax-loaders).
507+
508+
However, if you're using a syntaxes such as [`postcss-scss`](https://github.com/postcss/postcss-scss) or [`postcss-less`](https://github.com/webschik/postcss-less), they do not compile down to CSS. So if you are programmatically building a class name (see below), webpack will be able to generate the rendered CSS from SCSS/LESS, but `babel-plugin-react-css-modules` will not be able to parse the SCSS/LESS.
509+
510+
A SCSS example:
511+
512+
```scss
513+
$scales: 10, 20, 30, 40, 50;
514+
515+
@each $scale in $scales {
516+
.icon-#{$scale} {
517+
width: $scale;
518+
height: $scale;
519+
}
520+
}
521+
```
522+
523+
`babel-plugin-react-css-modules` will not receive `icon-10` or `icon-50`, but `icon-#{$scale}`. That is why you receive the error that `styleName` `"icon-10"` cannot be found.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /