React项目中的Tailwind-获取“无法找到模块'autoprefixer'"安装过程中出现错误 [英] Tailwind in React project - getting "Cannot find module 'autoprefixer'" error during setup
问题描述
我正在使用文档在 https上的React项目中设置Tailwind://tailwindcss.com/docs/guides/create-react-app .我一直在遵循这些步骤,但是当我到达应该运行 npx tailwindcss init
以便生成 tailwind.config.js
文件的部分时,,出现以下错误:
I'm following the documentation for setting up Tailwind in a React project over on https://tailwindcss.com/docs/guides/create-react-app. I've been following the steps, but when I get to the part where I'm supposed to run npx tailwindcss init
in order to generate a tailwind.config.js
file, I get the following error:
Cannot find module 'autoprefixer'
Require stack:
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli\commands\build.js
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli\commands\index.js
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli\main.js
- C:\Users\[user]\AppData\Roaming\npm-cache\_npx\16096\node_modules\tailwindcss\lib\cli.js
我已经检查我的 node_modules
文件夹中是否有 autoprefixer
,并尝试重新安装它,但是出现了同样的错误.在我的 package.json
中,我具有以下内容:
I've checked that I have autoprefixer
in my node_modules
folder and tried reinstalling it, but I get the same error. In my package.json
, I have the following:
...
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
...
根据文档.我的 craco.config.js
文件如下:
as per the documentation. My craco.config.js
file is as follows:
module.exports = {
style: {
postcss: {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
},
},
}
再次
,根据文档.我也尝试过重新安装 @ craco/craco
程序包无济于事,所以到现在为止,我一直处于困境.任何帮助将不胜感激.
again, as per the documentation. I've also tried reinstalling the @craco/craco
package to no avail, so at this point I'm stuck. Any help would be appreciated.
推荐答案
您可以尝试以下方法吗:
Can you try this:
npm uninstall tailwindcss postcss autoprefixer
npm install tailwindcss@latest postcss@latest autoprefixer@latest
npx tailwindcss init -p
npm uninstall tailwindcss postcss autoprefixer
npm install tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
此处: https://github.com/tailwindlabs/tailwindcss/issues/2831
这篇关于React项目中的Tailwind-获取“无法找到模块'autoprefixer'"安装过程中出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!