错误:使用 React Native 和 NativeWind 设置 Tailwind CSS 时,.plugins 不是有效的插件属性
问题:
我正在尝试使用 NativeWind 在我的 React Native 项目中设置 Tailwind CSS,但在运行应用程序时遇到以下错误:
bash 复制代码 错误:node_modules/expo-router/entry.js:[BABEL] ............/node_modules/expo-router/entry.js:.plugins 不是有效的插件属性 我做了什么:
安装了nativewind和tailwindcss。 根据NativeWind文档配置了babel.config.js和tailwind.config.js。 尝试回滚 Tailwind CSS 版本。 尝试调整 Babel 配置。 文件:
babel.config.js:
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ['nativewind/babel', 'react-native-reanimated/plugin'],
};
};
tailwind.config.js:`
module.exports = {
content: [
'./app/**/*.{js,jsx,ts,tsx}',
'./client/screens/**/*.{js,jsx,ts,tsx}',
'./client/components/**/*.{js,jsx,ts,tsx}',
],
presets: [require('nativewind')],
theme: {
extend: {},
},
plugins: [],
};
package.json 依赖项:
"dependencies": {
"@react-navigation/drawer": "^6.7.2",
"axios": "^1.7.7",
"cheerio": "^1.0.0",
"dotenv": "^16.4.5",
"expo": "~51.0.28",
"expo-constants": "^16.0.2",
"expo-linking": "^6.3.1",
"expo-location": "^17.0.1",
"expo-router": "^3.5.23",
"expo-status-bar": "^1.12.1",
"fs": "^0.0.1-security",
"install": "^0.13.0",
"moment": "^2.30.1",
"mongoose": "^8.7.2",
"mysql": "^2.18.1",
"nativewind": "^4.1.20",
"react": "18.2.0",
"react-native": "0.74.5",
"react-native-gesture-handler": "^2.20.0",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "^4.11.1",
"react-native-screens": "^3.34.0",
"tailwindcss": "3"
},
"devDependencies": {
"@babel/core": "^7.25.9",
"@babel/runtime": "^7.25.9"
},
"resolutions": {
"react-native-reanimated": "3.10.1"
},
app.d.ts:
/// <reference types="nativewind/types" />
附加信息:
我使用的是 Expo SDK 版本 ~51.0.28。 我已确保react-native-reanimated 已正确配置,并且其 Babel 插件列在插件数组的最后。 我尝试过清除缓存并重新安装node_modules。 问题:
什么可能导致我的设置中的 .plugins 不是有效的插件属性错误?我该如何解决这个问题,以便我可以将 Tailwind CSS 与 React Native 和 NativeWind 一起使用?
这是我的问题的解决方案:https://www.youtube.com/watch?v=dFRt3J0xx7E