mac 创建React Native项目遇到的问题
React Native创建项目遇到的问题
1.创建项目时提示:
⠧ Processing templateUsage Error: The nearest package directory (/Users/huang/Documents/develop/RN/myRn) doesn't seem to be part of the project declared in /Users/huang.
- If /Users/huang isn't intended to be a project, remove any yarn.lock and/or package.json file there.
看提示是缺少yarn.lock文件,进到目录内创建一个yarn.lock
huang@huangdeMacBook-Pro RN % cd myRn
huang@huangdeMacBook-Pro myRn % touch yarn.lock
2.创建项目时提示需要到ios目录执行 bundle install 、 bundle exec pod install 命令,执行 bundle install 后提示没有权限
huang@huangdeMacBook-Pro ios % bundle install
There was an error while trying to write to
`/Users/huang/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/versions.15001.tmp`.
It is likely that you need to grant write permissions for that path.
.bundle/设置读写权限后,再执行就成功了。
huang@huangdeMacBook-Pro ios % sudo chmod -R 777 /Users/huang/.bundle/
Password:
huang@huangdeMacBook-Pro ios % bundle install
- bundle exec pod install 报错,是没有安装依赖引起的。
huang@huangdeMacBook-Pro ios % bundle exec pod install
[!] Invalid `Podfile` file: [!] /Users/huang/.nvm/versions/node/v20.12.0/bin/node -p require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
) /Users/huang/Documents/develop/RN/myRn/ios
node:internal/modules/cjs/loader:1146
throw err;
^
Error: Cannot find module 'react-native/scripts/react_native_pods.rb'
Require stack:
- /Users/huang/Documents/develop/RN/myRn/ios/[eval]
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Function.resolve (node:internal/modules/helpers:190:19)
at [eval]:1:9
at runScriptInThisContext (node:internal/vm:209:10)
at node:internal/process/execution:109:14
at [eval]-wrapper:6:24
at runScript (node:internal/process/execution:92:62)
at evalScript (node:internal/process/execution:123:10)
at node:internal/main/eval_string:51:3 {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/huang/Documents/develop/RN/myRn/ios/[eval]' ]
}
返回项目主目录,执行 yarn install 安装按成后,再回到ios目录, 执行bundle exec pod install命令,就可以正常安装了
huang@huangdeMacBook-Pro myRn % cd ..
huang@huangdeMacBook-Pro myRn % yarn install
huang@huangdeMacBook-Pro myRn % cd ios
huang@huangdeMacBook-Pro ios % bundle exec pod install