【问题标题】:BABEL Cannot find module 'node:path' error react-nativeBABEL 找不到模块 \'node:path\' 错误 react-native
【发布时间】:2022-09-28 00:06:41
【问题描述】:

我正在尝试将 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\"
  },

    标签: javascript android react-native babeljs tailwind-css


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      问题是您的节点版本... 您需要做的就是将您的节点更新为最新版本, 删除 package.json node_modules 文件夹,然后 npm install

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          【解决方案4】:

          修复此错误所需要做的就是

          1. 安装最新版本的 Node js。

          2. 安装这个 Babel 插件 yarn add @babel/plugin-transform-react-jsx --dev

          3. 将此代码添加到您的 babel 配置 js "@babel/plugin-transform-react-jsx"

          【讨论】:

            【解决方案5】:

            只需按照此处的指南安装即可

            npm install nativewind
            npm install --save-dev tailwindcss
            

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

            【讨论】:

              猜你喜欢
              • 2021-10-28
              • 1970-01-01
              • 2020-01-13
              • 2016-10-27
              • 2021-11-26
              • 1970-01-01
              • 2019-02-24
              • 2019-05-13
              • 2019-07-30
              相关资源
              最近更新 更多