Jyo*_*moy 6 javascript android babeljs react-native tailwind-css
我正在尝试将tailwindcss-react-native包设置到我的 React Native 项目中。成功安装后,当我向组件添加类名时,会出现错误。我尝试卸载然后重新安装它,删除 npm 缓存和 node_modules 文件夹,但我无法弄清楚出了什么问题。我附上了错误日志以及我的项目的代码。请指出我在这里缺少什么。谢谢
我的 babel.config.js 文件:
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ["tailwindcss-react-native/babel"],
};
};
Run Code Online (Sandbox Code Playgroud)
我的 tailwind.config.js 文件:
module.exports = {
content: [
"./screens/**/*.{js,ts,jsx,tsx}",
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
Run Code Online (Sandbox Code Playgroud)
我的 App.js 文件:
import { TailwindProvider } from 'tailwindcss-react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './screens/HomeScreen';
const Stack = createNativeStackNavigator();
export default function App() {
return (
<NavigationContainer>
<TailwindProvider>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</TailwindProvider>
</NavigationContainer>
);
}
Run Code Online (Sandbox Code Playgroud)
我的 HomeScreen.js 屏幕:
import { View, Text } from 'react-native'
import React from 'react'
export default function HomeScreen() {
return (
<View>
<Text className="text-red-500">HomeScreen</Text>
</View>
)
}
Run Code Online (Sandbox Code Playgroud)
我的依赖项和开发依赖项:
"dependencies": {
"@react-navigation/native": "^6.0.11",
"@react-navigation/native-stack": "^6.7.0",
"expo": "~45.0.0",
"expo-status-bar": "~1.3.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-safe-area-context": "4.2.4",
"react-native-screens": "~3.11.1",
"react-native-web": "0.17.7",
"tailwindcss-react-native": "^1.7.10"
},
"devDependencies": {
"@babel/cli": "^7.18.6",
"@babel/core": "^7.18.6",
"@babel/node": "^7.18.6",
"tailwindcss": "^3.1.4"
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10954 次 |
| 最近记录: |