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.

Enabling JIT breaks sourcemaps in webpack + PostCSS project

See original GitHub issue

What version of Tailwind CSS are you using?

2.2.6

What build tool (or framework if it abstracts the build tool) are you using?

webpack 5.46.0, postcss 8.3.6

What version of Node.js are you using?

14.17.0

What browser are you using?

Chrome

What operating system are you using?

Ubuntu

Reproduction repository

Describe your issue

When using Tailwind’s JIT option for processing PostCSS in the webpack project, source maps are not being shown in the Chrome DevTools (but still generated in the output CSS file). The value of devtool option in the webpack config doesn’t matter, the result is the same.

With config like this:

  purge: [
    './src/**/*.tsx',
  ],
  mode: 'jit',

Source maps don’t get processed: Screenshot from 2021-07-22 16-36-57

When disabling the JIT option:

  purge: false,

Source maps are being processed properly, and the original file is shown in Chrome DevTools: Screenshot from 2021-07-22 16-30-51

I’ll bootstrap a repro repo if a more thorough investigation is needed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
MichaelRushtoncommented, Feb 9, 2022

Source maps are also not working properly in 3.0.19.

src/css/app.css

@tailwind base;
@tailwind components;
@tailwind utilities;

src/js/app.js

import '../css/app.css'

webpack.config.js

const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')

module.exports = (env, argv) =>
{

  process.env.NODE_ENV = argv.mode

  return {
    devtool: 'source-map',
    entry: {
      app: '/src/js/app.js'
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: 'babel-loader'
        },
        {
          test: /\.css$/,
          exclude: /node_modules/,
          use: [
            MiniCssExtractPlugin.loader,
            'css-loader',
            'postcss-loader',
          ],
        }
      ]
    },
    optimization: {
      minimize: true,
      minimizer: [
        `...`,
        new CssMinimizerPlugin(),
      ],
    },
    output: {
      chunkFilename: '[name].[contenthash].js',
      clean: true,
      filename: '[name].js',
      path: path.resolve(__dirname, 'public/dist')
    },
    plugins: [
      new MiniCssExtractPlugin({filename: '[name].css'})
    ]
  }

}

The generated public/dist/app.css.map includes this section:

"sources":["webpack://@test/test/./src/css/app.css","webpack://@test/test/./src/css/%3Cinput%20css%20doRbU6%3E","webpack://@test/test/<no source>"]

Using Chrome DevTools all the Tailwind CSS rules show as <no source>:1

2reactions
Xeeviscommented, Jan 30, 2022

Adding any regular css rule or even a simple comment will generate sourcemaps correctly.

<div class="with-sourcemap"></div>
<div class="with-another-sourcemap"></div>
<div class="no-sourcemap-here"></div>
.with-sourcemap {
  background-color: red;
  @apply h-4 w-4 bg-green-500;
}

.with-another-sourcemap {
  /* sourcemap will work here too */
  @apply h-4 w-4 bg-red-500;
}

.no-sourcemap-here {
  @apply h-4 w-4 bg-black;
}

image image image

Read more comments on GitHub >

github_iconTop Results From Across the Web

postcss-loader | webpack - JS.ORG
By default generation of source maps depends on the devtool option. All values enable source map generation except eval and false value. webpack.config.js...
Read more >
Speeding Up Tailwind CSS Builds - nystudio107
Learn how to optimize your Tailwind CSS PostCSS build times to make local development with Hot Module Replacement or Live Reload orders of ......
Read more >
webpack shows incorrect sourcemaps when using tailwibd ...
I'm using TailwindCSS 2.1+ in mode: 'jit' with SCSS, and currently facing the issue. Let say I created class .red .red { color:...
Read more >
How to Use Tailwind on a Svelte Site | CSS-Tricks
Let's spin up a basic Svelte site and integrate Tailwind into it for styling. One advantage of working with Tailwind is that there...
Read more >
Why we switched from Webpack to Vite - Hacker News
We adopted Vite early on for a large Vue project. ... You enable sourcemaps on Webpack with `devtool = "eval-source-map"` in your config, ......
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