简体   繁体   English

BABEL 找不到模块“节点:路径”错误 react-native

[英]BABEL Cannot find module 'node:path' error react-native

I'm trying to setup tailwindcss-react-native package into my react native project.我正在尝试将 tailwindcss -react-native package 设置到我的 react native 项目中。 After successful installation when I add classnames to a component it gives me an error.成功安装后,当我将类名添加到组件时,它会给我一个错误。 I've tried uninstalling and then re-installing it, removing the npm cache and node_modules folder but I can't figure out what is wrong.我试过卸载然后重新安装它,删除 npm 缓存和 node_modules 文件夹,但我不知道出了什么问题。 I'm attaching the error log and also codes of my project.我附上了错误日志以及我的项目的代码。 Please point out what I'm missing here.请指出我在这里缺少的东西。 Thank you谢谢

错误日志截图

My babel.config.js file:我的 babel.config.js 文件:

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

My tailwind.config.js file:我的 tailwind.config.js 文件:

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

My App.js file:我的 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>
    
  );
}

My HomeScreen.js screen:我的 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>
  )
}

My dependencies & dev dependencies:我的依赖项和开发依赖项:

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

The way i solved mine was to reinstall my app我解决我的方法是重新安装我的应用程序
Then after it has been installed I removed the package-lock.json and node_modules and reinstalled tailwind-css-react-native and did a the setup in the documentation and it worked.然后在安装之后,我删除了 package-lock.json 和 node_modules 并重新安装了 tailwind-css-react-native 并在文档中进行了设置并且它起作用了。

For everyone who is getting this error, the solution is to update Node at least on 14.18.0 .对于遇到此错误的每个人,解决方案是至少在14.18.0上更新Node
The tailwindcss-react-native package is trying to access the node:path variable that is available from version 14.18.0` tailwindcss-react-native包正在尝试访问node:path变量,该变量可从版本 14.18.0 `

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

All you need do to fix this error is to修复此错误所需要做的就是

  1. install the latest version of Node js.安装最新版本的 Node js。

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

  3. Add this code to your babel config js "@babel/plugin-transform-react-jsx"将此代码添加到您的 babel 配置 js "@babel/plugin-transform-react-jsx"

Just follow the guide here by installing只需按照此处的指南安装即可

npm install nativewind
npm install --save-dev tailwindcss

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:index.js: [BABEL]: 在 react-native 中找不到模块 'node:fs' - error: index.js: [BABEL]: Cannot find module 'node:fs' in react-native 运行测试时无法从“node_modules/react-native/jest/setup.js”中找到模块“@babel/runtime/helpers/interopRequireDefault” - Cannot find module '@babel/runtime/helpers/interopRequireDefault' from 'node_modules/react-native/jest/setup.js' when I run tests 找不到模块'react-native' - Cannot Find Module 'react-native' 找不到模块&#39;setupDevtools&#39;React-Native - Cannot find module 'setupDevtools' React-Native 错误:找不到模块“ reative-native” /未找到模块:错误:无法解析模块“ react-native-web” - Error: Cannot find module “react-native” / Module not found: Error: Cannot resolve module 'react-native-web' React Native Typescript babel-plugin-module-resolver 错误:找不到模块或其对应的类型声明 - React Native Typescript babel-plugin-module-resolver error: Cannot find module or its corresponding type declerations Babel 模块解析器不适用于 react-native - Babel module resolver not working with react-native 捆绑失败:错误:无法从&#39;/ workspace / reactnative找到模块&#39;babel-preset-react-native&#39; - bundling failed: Error: Cannot find module 'babel-preset-react-native' from '/workspace/reactnative'' 错误:[BABEL]:在 react-native-builder-bob 中找不到模块“./built-in-definitions” - Error: [BABEL]: Cannot find module './built-in-definitions' in react-native-builder-bob 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):错误:找不到模块“babel-preset-react” - Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-preset-react'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM