I tried to reproduce the minimal example on the homepage, but the console.log to log the css from the main class. Instead it logs undefined.
From the homepage:
index.html
<html>
<body>
<script src="./index.js"></script>
</body>
</html>
index.js
// import another component
import main from './main';
main();
main.js
// import a CSS module
import classes from './main.css';
export default () => {
console.log(classes.main);
};
main.css
.main {
/* Reference an image file */
/* background: url('./images/background.png'); */
color: red;
}
Then using the npm script "start": "parcel index.html" to start the web server.
I would expect the console.log to show the contents of the main css class.
Console.log shows undefined instead.
This also happens when I create a production build, when I switch to the latest Node version and when I use Firefox..
Maybe I am doing something wrong, am I missing a dependency?
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.9.7
| Node | v8.11.4
| npm/Yarn | 5.6.0
| Operating System | OSX
You have to enable modules in postcss config. As documented: https://parceljs.org/transforms.html#postcss
It should probably not use css modules on the getting started guide
Ah yes, now it works! Thanks.
I agree that ideally the example on the frontpage should require little of no further configuration.
Glad I could help. Feel free to contribute back to the docs with a sidenote or updated example :)
Most helpful comment
You have to enable modules in postcss config. As documented: https://parceljs.org/transforms.html#postcss
It should probably not use css modules on the getting started guide