score:7
This is mostly just bad news.
Create React App's Tailwind support means that they will detect tailwind.config.js
in the project and add tailwindcss
to their existing postcss
configuration. Source in CRA
The guide that Tailwind offers on their site creates a dummy postcss.config.js
- Making changes in this file does not change the actual postcss configuration. (misleading if anything)
This is a known issue currently - Github discussion on Tailwind support PR between Adam Wathan (Tailwind founder) and Ian Sutherland (CRA maintainer). But it does not seem like there is an intention to be fixed soon.
If you want to use nesting (or any PostCSS plugin really) is to eject from CRA using:
npm run eject
After ejecting you can find CRA's postcss configuration in config/webpack.config.js
- look for postcss-loader
. Editing the configuration there can enable any postcss features.
PS: Look out for postcss-preset-env
in the default configuration while enabling nesting. Tailwind requires you to edit configuration if this is present.
score:0
acording to @aricma answer, is easier if you create a script.js file on parent directory (same as package.json) and add this on package.json
"scripts": {
"postinstall": "node script.js",
...
}
and this on script.js
const fs = require('fs');
fs.readFile('node_modules/react-scripts/config/webpack.config.js', 'utf8', (err, data) => {
if (err) {
return console.log(err);
}
const result = data.replace("'postcss-flexbugs-fixes',", "'postcss-flexbugs-fixes','postcss-nesting',").replace("'tailwindcss',", "'tailwindcss/nesting', 'tailwindcss',");
fs.writeFile('node_modules/react-scripts/config/webpack.config.js', result, 'utf8', (err) => {
if (err) {
return console.log(err);
}
return console.log(true);
});
return console.log(true);
});
score:2
I use CRA and to fix the issue I used postinstall
to run a script after npm install
or yarn
. The script is changing the web pack config of CRA after all dependencies are installed(a temporary solution of cause).
You can find the web pack config in node_modules/react-scripts/config/webpack.config.js
.
The script adds my postcss packages to the actual CRA web pack config.
WHY? CRA does not respect any postcss config in your repo
Have also a look at this comment to see how you should use postinstall
https://github.com/facebook/create-react-app/issues/2133#issuecomment-347574268.
I also added tailwindcss/nesting
before tailwindcss
because tailwind is throwing a warning when it sees any nested css. The warning was blocking my CI since CI=true in CRA means all warnings are treated as errors.
Here is the script that is running in my repo.
FILE="node_modules/react-scripts/config/webpack.config.js"
function replace {
TARGET_FILE=$1
PATTERN_TO_FIND=$2
VALUE_FOR_REPLACEMENT=$3
OLD_FILE_CONTENT=$(cat "$TARGET_FILE") # we need to collect the content of the file so we can overwrite it in the next command
echo "$OLD_FILE_CONTENT" | sed -e "s/$PATTERN_TO_FIND/$VALUE_FOR_REPLACEMENT/g" > "$TARGET_FILE"
}
# add postcss-nesting
replace "$FILE" "'postcss-flexbugs-fixes'," "'postcss-flexbugs-fixes','postcss-nesting',"
# add tailwind/nesting
replace "$FILE" "'tailwindcss'," "'tailwindcss\/nesting', 'tailwindcss',"
Source: stackoverflow.com
Related Query
- Getting the error "Nested CSS was detected, but CSS nesting has not been configured correctly" in React app?
- Getting an error "A non-serializable value was detected in the state" when using redux toolkit - but NOT with normal redux
- ValidationError: Invalid options object. CSS Loader has been initialised using an options object that does not match the API schema
- Jest testing onClick() gets error 'Expected mock function to have been called, but it was not called.'
- Even if a state has been changed, but the view has not been rendered again in React / Next.js
- MalformedSecurityHeader error in signed url - Header was included in signedheaders, but not in the request
- React: Muuri-react generate random items error - Uncaught Invariant: Invariant failed: The item has not been setted yet
- I am trying to start a new react project But I am getting this error and the app is not created. I have installed react globally
- Trying to add an array of objects using react useState but getting the error 'Objects are not valid as a React child (found: object with keys {})'
- once the data has been fetched the state value are not getting updated
- i`m getting the 400 response error in react.js i know the backendd is ok but the client side i am not sure i am not fimiliar with react
- Getting error error rejection promise of the file tried to fix it but its not working
- I'm getting an error message "undefined has no properties" but don't understand where the problem occurs
- Why am I getting an error with cors in ExpressJS in one case, but not the other?
- AutoComplete(MUI) I am trying to set a default Value in the checkbox from an API, but getting (intermediate value).filter is not a function error
- I am trying to update the state using the React useState hook?? The Create Read and Delete part has been done but iam not able to update
- Error "A state mutation was detected between dispatches" in spite of modifying temporary object array and not the state
- React-Native: Application has not been registered error
- Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema
- "React has detected a change in the order of Hooks" but Hooks seem to be invoked in order
- error TS2602: JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist
- Invalid options object. Dev Server has been initialized using an options object that does not match the API schema
- Jest Expected mock function to have been called, but it was not called
- How to fix the console warning "The resource ... was preloaded using link preload but not used within a few seconds from the window's load event"?
- Why am I getting the error message "Property 'then' does not exist on type 'AsyncThunkAction'"?
- Webpack error: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema
- Jest test passes but .. has console message You are trying to access a property or method of the Jest environment after it has been torn down
- Module not found: can't resolve' redux-thunk ' error I have tried the solutions but it does not happen.What is the solution?
- BlueprintJS is not loading its icon CSS module, but is able to load the core CSS module
- React has detected a change in the order of Hooks called, but I can't see any hooks being called conditonally
More Query from same tag
- AG-GRID field is not found in case of optional field in JSON data
- javascript iframe set timer and check if loaded
- React-Redux TypeScript Errors
- React Modifying Textarea Values
- Is there a way to get RGB value from a live camera feed in reactJs?
- why does useEffect run once the window.innerWidth changes even though the second param in it is an empty array
- @parcel/transformer-css: Unknown at rule: @tailwind
- Create icon with inkscape and import it with material ui SvgIcon
- Is there any way to know the useParams from the top container?
- How to use country flags in node and react
- Control multiple checkboxes in Material UI
- Sharing on React JS Mobile application
- Trigger hard cache refresh when index.html changes in create-react-app deployment
- How do i display Breadcrumb name conditionally on response from child.in React with hooks?
- enzyme test / react for keyDown (shift) for stopImmediatePropogation
- Dynamically add React components into DIV or another react App
- React-Redux action is not dispatched properly?
- Wordpress to React REST API : Objects are not valid as a React child (found: object with keys {rendered})
- Critical dependency warning when using react-pdf
- antd Table onRow onClick to another component
- Checkbox click works 2 times
- React routing to a page with dynamically determined slug
- npm error: 'specify configs in the ini-formatted file:' \User\.npmrc
- How to hide the sidebar from perticular page in react.js?
- Connecting my React App to a MySQL Database on a PHP Server
- how to render object array in react?
- Can't center and space card deck for react js bootstrap
- No routes matched location "/cart" in router router dom v 6
- How to deal with a query parameter in react router
- React hook useCallback without dependencies