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.

JIT watch issue with Webpack and React element

See original GitHub issue

What version of Tailwind CSS are you using?

v3.0.15

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

webpack 4.44.1, React 17.0.2, postcss 8.4.5

What version of Node.js are you using?

v12.5.0

What browser are you using?

Chrome

What operating system are you using?

Windows

Reproduction URL

Describe your issue

Hey guys

I have an issue with the JIT compiler of the Tailwind CSS v3 while I didn’t have the same issue when I used v2. But please note that I didn’t enable JIT in the v2.

The JIT compiler can not track changes and produce CSS from the classes added to the react element.

I tried to enable the TAILWIND_MODE=watch but it can not help.

Webpack config is as follows.

const webpackConfig = {
	mode: NODE_ENV,
	entry: {
		admin: './assets/js/dev/admin/index.js',
	},
	output: {
		filename: './assets/js/admin/[name]/index.js',
		path: __dirname,
		library: [ '[modulename]' ],
		libraryTarget: 'this',
	},
	externals,
	module: {
		rules: [
			{
				parser: {
					amd: false,
				},
			},
			{
				test: /\.(js|jsx)$/,
				exclude: /node_modules/,
				loaders: [ 'babel-loader' ],
			},
			{ test: /\.md$/, use: 'raw-loader' },
			{
				test: /\.s?css$/,
				use: [
					MiniCssExtractPlugin.loader,
					'css-loader',
					{
						loader: 'postcss-loader',
						options: { postcssOptions: postcssConfig },
					},
				],
			},
			{
				test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
				loader: 'url-loader',
			},
		],
	},
	resolve: {
		extensions: [ '*', '.js', '.jsx' ],
		alias: aliases,
	},
	plugins: [
		new CustomTemplatedPathPlugin( {
			modulename( outputPath, data ) {
				const entryName = get( data, [ 'chunk', 'name' ] );
				if ( entryName ) {
					return entryName.replace( /-([a-z])/g, ( match, letter ) =>
						letter.toUpperCase()
					);
				}
				return outputPath;
			},
		} ),
		new MiniCssExtractPlugin( {
			filename: './assets/css/[name]/style.css',
		} ),
	],
};

The Tailwind CSS config is:

const colors = require( 'tailwindcss/colors' );

module.exports = {
	important: '.asnp-app',
	prefix: 'asnp-',
	content: [
		'./assets/js/dev/**/*.{js,jsx,ts,tsx,vue,html}',
		'./assets/js/dev/**/*.jsx',
	],
	theme: {
		extend: {},
		colors: {
			transparent: 'transparent',
			current: 'currentColor',
			white: colors.white,
			black: colors.black,
			gray: colors.gray,
			rose: colors.rose,
			indigo: colors.indigo,
			green: colors.green,
			blue: colors.blue,
		},
	},
	plugins: [],
	corePlugins: {
		preflight: false,
	},
};

The postcss config is:

const autoprefixer = require( 'autoprefixer' );
const tailwindcss = require( 'tailwindcss' );

module.exports = {
	plugins: [
		require( 'postcss-import' ),
		require( 'tailwindcss/nesting' ),
		tailwindcss,
		autoprefixer,
	],
};

The package.json script is:

"scripts": {
		"prepack": "npm install && npm run lint && npm run test && npm run build",
		"build": "cross-env BABEL_ENV=production NODE_ENV=production webpack",
		"start": "cross-env NODE_ENV=development TAILWIND_MODE=watch BABEL_ENV=development webpack --mode development --watch --info-verbosity none",
		"lint": "npm run lint:php && npm run lint:css && npm run lint:js",
		"lint:php": "composer run-script phpcs .",
		"lint:css": "stylelint assets/css",
		"lint:js": "eslint assets/js --ext=js,jsx"
	},

React element code:

export default function Settings() {
	const [ settings, setSettings ] = useState( {
		name: 'Name',
	} );

	const updateSettings = ( field, value ) => {
		let update = Object.assign( {}, settings, { [ field ]: value } );
		setSettings( update );
	};

	return (
		<div className="asnp-mt-4 asnp-max-w-lg asnp-grid asnp-grid-cols-1 asnp-gap-6">
			<label className="asnp-block asnp-space-y-1">
				<span className="asnp-field-title">
					{ __( 'Name', 'easy-woocommerce-discounts' ) }
				</span>
				<input
					type="text"
					className="asnp-block asnp-text-field"
					value={ settings.name }
					onChange={ ( e ) =>
						updateSettings( 'name', e.target.value )
					}
				/>
			</label>
			<div className="asnp-flex">
				<div className="asnp-w-1/2 asnp-bg-rose-500">w-1/2</div>
				<div className="asnp-w-1/2 asnp-bg-indigo-500">w-1/2</div>
			</div>
			<div className="asnp-flex">
				<div className="asnp-w-1/2 asnp-h-10 asnp-bg-gray-500">
					w-1/2
				</div>
				<div className="asnp-w-1/2 asnp-h-10 asnp-bg-blue-500 asnp-text-white">
					w-1/2
				</div>
			</div>
		</div>
	);
}

In the above example when I change the color of an element with a class like asnp-bg-green-500 it does not take effect while I restart the npm start.

Thanks in advance for your help.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
reininkcommented, Jan 20, 2022

@codewp Thanks for sharing this. Reviewing your project’s dependencies, I can see that the css-loader package that you have installed is requiring PostCSS 7:

https://github.com/codewp/tl-tailwindcss-repro-7113/blob/64123d3e92eca7110370988f2b641ec2a23428da/package.json#L13

The best way to figure this out is by looking at your package-lock.json file, and then searching for all instances of "postcss": "^7. For example:

https://github.com/codewp/tl-tailwindcss-repro-7113/blob/64123d3e92eca7110370988f2b641ec2a23428da/package-lock.json#L1691

I’m going to close this issue, as it sounds like the culprit here is PostCSS 7. For anyone else who stumbles across this issue, be sure to review your dependencies for instances of PostCSS 7 👍

0reactions
codewpcommented, Jan 20, 2022

@reinink Thank you for your suggestion.

I created a reproduction and it worked. The reproduction is at the below repo. https://github.com/codewp/tl-tailwindcss-repro-7113

npm install
npm start

In the dist folder open the index.html

How can I detect that which dependencies are using postcss older versions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

JIT doesn't seem to be watching and recompiling files ... - GitHub
It appears local webpack-dev-server builds are not recompiling the TailwindCSS at all, I make a change to a component, webpack will watch ......
Read more >
Using Webpack with React, Pt. 1 - Toptal
In this Webpack tutorial, we demystify Webpack/React configuration. Go beyond Create React App with Webpack customization tailored to the needs of your app....
Read more >
How to enable JIT(Just in time mode) with create react app?
"start": "cross-env TAILWIND_MODE=watch craco start" ... terminal and do npm start and your development server is ready with JIT compiler.
Read more >
Just-in-Time Mode - Tailwind CSS
Tailwind CSS v2.1 introduces a new just-in-time compiler for Tailwind CSS that ... See the troubleshooting section to learn how to fix common...
Read more >
You Don't Need Create-React-App. Webpack ... - Sviat Kuzhelev
In case of React-based code-producing systems it's obviously to know that today we don't have something even better than starter kit from Facebook...
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