[英]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修复此错误所需要做的就是
install the latest version of Node js.安装最新版本的 Node js。
Install this Babel plugin yarn add @babel/plugin-transform-react-jsx --dev安装这个 Babel 插件 yarn add @babel/plugin-transform-react-jsx --dev
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.