Parcel 2 cache problem on file changes during the build (CSS Modules with Astroturf)
See original GitHub issue🐛 bug report
When you are using Astroturf (a tool which moves CSS-in-JS declarations to separated CSS Modules files) Parcel 2 nightly cleans CSS Modules export on any file changes.
But it works fine on --no-cache.
🎛 Configuration (.babelrc, package.json, cli command)
package.json:
{
"private": true,
"scripts": {
"start": "parcel serve index.html",
"start:fixed": "parcel serve index.html --no-cache"
},
"dependencies": {
"@babel/core": "^7.12.9",
"astroturf": "^0.10.5",
"parcel": "^2.0.0-nightly.462",
"postcss": "^8.0.0",
"postcss-modules": "^3.2.2"
}
}
.babelrc:
{
"plugins": [
["astroturf/plugin", {
"extension": ".module.css"
}]
]
}
.postcssrc:
{
"plugins": {
"postcss-modules": {}
}
}
index.js:
import { css } from 'astroturf'
let styles = css`
.button {
background: blue;
}
`
document.body.innerHTML = JSON.stringify(styles)
I way to reproduce an error:
- Clone repo with error
yarn start- Open
localhost:1234browser - See something like
{"button":"_button_c6258"}in the browser touch index.jsto force Parcel rebuilding- Reload the page in the browser
🤔 Expected Behavior
Continue to see {"button":"_button_c6258"} in the browser
😯 Current Behavior
The browser will show {}, which mean that CSS Modules stopped to work.
If I will open the JS bundle I will see that the CSS file is empty.
💁 Possible Solution
If you will run yarn start:fixed (with --no-cache) everything will work correctly.
Seems like there is an issue in the cache system, which I was not able to detect.
🔦 Context
CSS Modules without Astroturf is working. I understand that my Astroturf use case is rare (but I still think that Astroturf is the best CSS-in-JS solution).
But this bug can show some deep bug in the cache system, which could affect many other use cases.
💻 Code Sample
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 2.0.0-nightly.462 |
| Node | 12.20 |
| npm/Yarn | 1.22.10 |
| Operating System | Fedora 33 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
Cool! Closing it.
Technically, we can convince the Astroturf team to create a Parcel transformer with in-memory complications. But I saw a few code generators even for Webpack because there are bloody edge cases. Especially for GraphQL.