javascript BABEL找不到模块'node:path'错误React-本机

tf7tbtn2  于 2022-10-30  发布在  Java
关注(0)|答案(5)|浏览(153)

我正在尝试将tailwindcss-react-native包安装到我的react原生项目中。成功安装后,当我将类名添加到组件时,它给我一个错误。我尝试卸载然后重新安装它,删除npm缓存和node_modules文件夹,但我无法找出错误所在。我附上了错误日志和我的项目代码。请指出我在这里遗漏了什么。谢谢

我的babel.config.js文件:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ["tailwindcss-react-native/babel"],
  };
};

我的tailwind.config.js文件:

module.exports = {
  content: [
    "./screens/**/*.{js,ts,jsx,tsx}",
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

我的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>

  );
}

我的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>
  )
}

我的依赖项和开发依赖项:

"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"
  },
vuv7lop3

vuv7lop31#

问题出在您的节点版本上...您需要做的就是更新您的节点以获得最新版本,删除package.json node_modules文件夹,然后安装npm

ttp71kqs

ttp71kqs2#

我解决我的方法是重新安装我的应用程序
然后在它安装后,我删除了package-lock.json和node_modules,重新安装了tailwind-css-react-native,并在文档中进行了设置,它工作了。

bq3bfh9z

bq3bfh9z3#

对于遇到此错误的每个人,解决方案是至少在14.18.0上更新Node
tailwindcss-react-native软件包试图访问node:path变量,该变量可从版本14.18.0中获得。

5ktev3wc

5ktev3wc4#

要修复此错误,您只需执行以下操作
1.请安装最新版本的Node js。
1.安装这个巴别塔插件纱add @巴别塔/plugin-transform-react-jsx --dev
1.将此代码添加到您的Babel配置js“@Babel/plugin-transform-react-jsx”

qcuzuvrc

qcuzuvrc5#

只需按照此处的指南安装

npm install nativewind
npm install --save-dev tailwindcss

https://www.nativewind.dev/guides/babel

相关问题