We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
style-loader 2.0 now returns ES module and breaks Astroturf’s require()
style-loader
require()
Right now code like:
const styles = css` .button { color: black; border: 1px solid black; background-color: white; } ` console.log(styles.button)
will be compiled by astroturf/loader to:
astroturf/loader
const styles = require('./index-styles.astroturf.pcss') console.log(styles)
But webpack 4 will return ESM module on .astroturf.pcss import:
.astroturf.pcss
{ __esModule: true default: { button: "index-styles-astroturf_button-9b607" } }
As the result, styled doesn’t work because it expects to get { cls1, cls2 } from require but gets { __esModule: true, … }
styled
{ cls1, cls2 }
require
{ __esModule: true, … }
module.exports = { mode: IS_PRODUCTION ? 'production' : 'development', devtool: IS_PRODUCTION ? false : 'eval-cheap-module-source-map', entry: { app: join(__dirname, 'src', 'index.tsx') }, output: { publicPath: '/', filename: '[name].[hash:8].js', chunkFilename: '[name]-[id].[hash:8].js' }, devServer: { hot: true, open: true }, plugins, module: { rules: [ { test: /\.tsx?$/, use: [ { loader: 'babel-loader' }, { loader: 'astroturf/loader', options: { extension: '.astroturf.pcss' } } ] }, { test: /\.astroturf\.pcss$/, use: [ IS_PRODUCTION ? MiniCssExtractPlugin.loader : 'style-loader', { loader: 'css-loader', options: { importLoaders: 1, modules: true } }, { loader: 'postcss-loader' } ] } ] } }
import
The text was updated successfully, but these errors were encountered:
I have esm support in the v1 branch, we should probably back port if it's not too much trouble
Sorry, something went wrong.
It will be great and improve onboarding
Another solution is to just turn off the esModule with style-loader option like this: { loader: 'style-loader', options: { esModule: false, } },
{ loader: 'style-loader', options: { esModule: false, } },
btw. MiniCssExtractPlugin has also that option in case you hit the same issue with production build..
No branches or pull requests
style-loader
2.0 now returns ES module and breaks Astroturf’srequire()
Right now code like:
will be compiled by
astroturf/loader
to:But webpack 4 will return ESM module on
.astroturf.pcss
import:As the result,
styled
doesn’t work because it expects to get{ cls1, cls2 }
fromrequire
but gets{ __esModule: true, … }
Details
Possible solutions
import
{ __esModule: true, … }
unwrapperThe text was updated successfully, but these errors were encountered: