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

Error when ctx.options.map is being used in postcss.config.js #497

Closed
ikornienko opened this issue Nov 18, 2020 · 4 comments · Fixed by #498
Closed

Error when ctx.options.map is being used in postcss.config.js #497

ikornienko opened this issue Nov 18, 2020 · 4 comments · Fixed by #498

Comments

@ikornienko
Copy link

  • Operating System: macOS Catalina
  • Node Version: 14.15.1
  • NPM Version: 6.14.8
  • webpack Version: 4.42.1
  • postcss-loader Version: 4.0.4

Expected Behavior

No failure with the valid postcss.config.js.

Actual Behavior

Seeing an error

Module build failed (from ./node_modules/gatsby-plugin-postcss/node_modules/postcss-loader/dist/cjs.js):
TypeError: Cannot read property 'map' of undefined
    at Object.module.exports [as config] (project_dir/postcss.config.js:84:20)
    at loadConfig (project_dir/node_modules/gatsby-plugin-postcss/node_modules/postcss-loader/dist/utils.js:89:28)
    at async Object.loader (project_dir/node_modules/gatsby-plugin-postcss/node_modules/postcss-loader/dist/index.js:53:22)

Code

postcss.config.js (especially line 84 mentioned in the error) has a config

module.exports = (ctx) => ({
  map: ctx.options.map,  // this one is line 84
  plugins: [
    ...

It's a valid syntax as specified in postcss-cli docs, and postcss-cli works fine on it, only when this config is being loaded by postcss-loader in the context of gatsby-plugin-postcss then it fails.

Additional Context

It happens during the Gatsby build, when gatsby-plugin-postcss uses postcss-loader to read the config. I have NOT opened an issue with gatsby-plugin-postcss. The project is using gatsby-plugin-postcss version 3.1.0.

@ikornienko
Copy link
Author

Not sure if it can be related to #480 because a different loader is now being used.

@alexander-akait
Copy link
Member

It's a valid syntax as specified in postcss-cli docs, and postcss-cli works fine on it, only when this config is being loaded by postcss-loader in the context of gatsby-plugin-postcss then it fails.

We don't have compatibility with webpack-cli due it was abandoned a long time, I will try to fix it

@alexander-akait
Copy link
Member

alexander-akait commented Nov 19, 2020

Also I think you need to open an issue in postcss-cli repo, because many things are really weird and I don't want to implement them here:

But I can pass postcssOptions from the loader to your config for keeping some compatibility

@ikornienko
Copy link
Author

@evilebottnawi thank you for the response and a light speed fix + release! The concerns you bring about postcss-cli are indeed disturbing. I don't have all the context, TBH I haven't worked with postcss-cli too close. Just happened to be helping on a project that actively uses it, and on that project the attempt to upgrade gatsby-plugin-postcss broke the build because of the issue you just fixed :)

Thank you again for such an outstanding project maintenance discipline with this quick fix!

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

Successfully merging a pull request may close this issue.

2 participants