question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CRA5 app fails to build due to Invalid mapping error in Css Minimizer plugin

See original GitHub issue

Describe the bug

(Originally reported as https://github.com/tailwindlabs/tailwindcss/issues/7687, but closed and moved to a discussion by @adamwathan, so I assume he believes the problem does not lie there.)

In a vanilla CRA 5 app configured with Tailwind 3, the project fails to build if a CSS rule using Tailwind’s @apply directive together with a background color rule is included. Removing the background color from the custom selector avoids the problem.

UPDATE: @thecrypticace has demonstrated that the issue is not dependent on Tailwind, but also occurs when using standard CSS.

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

build, minify, css

Environment

Environment Info:

current version of create-react-app: 5.0.0 running from /Users/stephen/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

System: OS: macOS 12.1 CPU: (10) x64 Apple M1 Pro Binaries: Node: 14.17.5 - /usr/local/bin/node Yarn: 1.22.11 - ~/.npm-global/bin/yarn npm: 8.5.2 - ~/.npm-global/bin/npm Browsers: Chrome: 98.0.4758.109 Edge: Not Found Firefox: 96.0.3 Safari: 15.2 npmPackages: react: ^17.0.2 => 17.0.2 react-dom: ^17.0.2 => 17.0.2 react-scripts: 5.0.0 => 5.0.0 npmGlobalPackages: create-react-app: Not Found

Steps to reproduce

Sample project to reproduce issue: https://github.com/stephent/cra-5-tw-3-build-fails

  1. Download main branch of sample project
  2. Install dependencies npm i
  3. Run npm run build

Expected behavior

Should build successfully

Actual behavior

Build fails with the following error:

Failed to compile.

static/css/main.4bacc579.css from Css Minimizer plugin
Error: Invalid mapping: {"generated":{"line":3,"column":8651},"source":"static/css/main.4bacc579.css","original":{"line":330,"column":null},"name":null}

Reproducible demo

https://github.com/stephent/cra-5-tw-3-build-fails

  1. Download source, install dependencies
  2. Build project
  3. Build fails as described above
  4. The project includes a file ./styles/custom.css with a single selector, .my-class. Edit line 2 and delete the applied rule bg-white
  5. The project builds successfully

I tried a few different rules here and only managed to reproduce the build error when a background color rule was used.

I could not find any open bug reports against css-minimizer-webpack-plugin for ‘Invalid mapping’ errors, and given that CRA doesn’t expose webpack config by default, I wonder if there’s an issue with what gets passed in to the css minimizer.

(I did also try customizing the css minimizer config via craco to use different minification approaches, but they all fail in the same way, suggesting the problem may lie upstream of that step.)

See also

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
aicommented, Feb 28, 2022

Thanks. I will look (but maybe on next week, protests against Russian-Ukranian war takes all my resources).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run Build command in React is giving me Error: Invalid Mapping
I believe the problem lies in postcss . I'm able to build successfully by force downgrading postcss to 8.4.5 in package.json :
Read more >
Error Building : r/reactjs - Reddit
Failed to compile. static/css/main.f563a0f4.css from Css Minimizer plugin Error: Invalid mapping: {"generated":{"line":6,"column":160493} ...
Read more >
Minifying - SurviveJS
css -minimizer-webpack-plugin is a plugin-based option that applies a chosen minifier on CSS assets. Using MiniCssExtractPlugin can lead to duplicated CSS ...
Read more >
My experience migrating a React App from Create-React-App ...
I received two major errors after the update, the first one was related to CSS-In-Modules in combination with SASS: Invalid dependencies have ...
Read more >
The best webpack configurations for React applications
Create React App (CRA) ships with webpack already under the hood, but usually, ... We'll use more of these webpack plugins as we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found