首页 > 解决方案 > React Native 项目通过 react native CLI 创建和运行错误

问题描述

我是反应原生开发的新手。我正在使用带有 M1 芯片的新 MacBook Air(M1,2020)。我已经安装了:

Node version 14.15.3, 
Homebrew version 2.7.0, 
Xcode Version 12.3

当我尝试通过 react native cli 创建一个新项目时,出现以下错误:

sudo react-native init test
Password:
This will walk you through creating a new React Native project in /Users/alimran/workspace/reactnative/prod/test
Installing react-native...
Consider installing yarn to make this faster: https://yarnpkg.com
npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated

> fsevents@1.2.13 install /Users/alimran/workspace/reactnative/prod/test/node_modules/fsevents
> node install.js

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/alimran/workspace/reactnative/prod/test/node_modules/fsevents/build'
gyp ERR! System Darwin 20.1.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/alimran/workspace/reactnative/prod/test/node_modules/fsevents
gyp ERR! node -v v14.15.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 

> core-js@2.6.12 postinstall /Users/alimran/workspace/reactnative/prod/test/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN react-native@0.63.4 requires a peer of react@16.13.1 but none is installed. You must install peer dependencies yourself.
npm WARN use-subscription@1.5.1 requires a peer of react@^16.8.0 || ^17.0.0 but none is installed. You must install peer dependencies yourself.

+ react-native@0.63.4
added 732 packages from 414 contributors and audited 732 packages in 310.649s

12 packages are looking for funding
  run `npm fund` for details

found 3 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
info Setting up new React Native app in /Users/alimran/workspace/reactnative/prod/test
(node:2294) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
info Adding required dependencies
+ react@16.13.1
added 1 package and audited 735 packages in 4.828s

12 packages are looking for funding
  run `npm fund` for details

found 3 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
info Adding required dev dependencies
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.npmjs.org/object.values failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/alimran/.npm/_logs/2020-12-25T16_12_07_249Z-debug.log
(node:2294) UnhandledPromiseRejectionWarning: Error: Command failed: npm install --save-dev --save-exact @babel/core @babel/runtime @react-native-community/eslint-config eslint jest babel-jest metro-react-native-babel-preset react-test-renderer@16.13.1
    at makeError (/Users/alimran/workspace/reactnative/prod/test/node_modules/execa/index.js:174:9)
    at /Users/alimran/workspace/reactnative/prod/test/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async generateProject (/Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/init/initCompat.js:128:3)
    at async Object.initCompat (/Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/init/initCompat.js:105:3)
(node:2294) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:2294) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

当我尝试运行应用程序时,出现以下错误:

react-native run-ios
warn Package @react-native-community/eslint-config has been ignored because it contains invalid configuration. Reason: Cannot find module '@react-native-community/eslint-config/package.json'
Require stack:
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/config/resolveNodeModuleDir.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/releaseChecker/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/runServer.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/start.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/cli.js
- /usr/local/lib/node_modules/react-native-cli/index.js
warn Package babel-jest has been ignored because it contains invalid configuration. Reason: Cannot find module 'babel-jest/package.json'
Require stack:
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/config/resolveNodeModuleDir.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/releaseChecker/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/runServer.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/start.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/cli.js
- /usr/local/lib/node_modules/react-native-cli/index.js
warn Package eslint has been ignored because it contains invalid configuration. Reason: Cannot find module 'eslint/package.json'
Require stack:
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/config/resolveNodeModuleDir.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/releaseChecker/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/runServer.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/start.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/cli.js
- /usr/local/lib/node_modules/react-native-cli/index.js
warn Package jest has been ignored because it contains invalid configuration. Reason: Cannot find module 'jest/package.json'
Require stack:
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/config/resolveNodeModuleDir.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/releaseChecker/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/runServer.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/start.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/cli.js
- /usr/local/lib/node_modules/react-native-cli/index.js
warn Package react-test-renderer has been ignored because it contains invalid configuration. Reason: Cannot find module 'react-test-renderer/package.json'
Require stack:
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/config/resolveNodeModuleDir.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/tools/releaseChecker/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/runServer.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/start/start.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/commands/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js
- /Users/alimran/workspace/reactnative/prod/test/node_modules/react-native/cli.js
- /usr/local/lib/node_modules/react-native-cli/index.js
error Could not find "Podfile.lock" at /Users/alimran/workspace/reactnative/prod/test/ios/Podfile.lock. Did you run "pod install" in iOS directory?
info Found Xcode project "test.xcodeproj"
info Building (using "xcodebuild -project test.xcodeproj -configuration Debug -scheme test -destination id=06B32499-BA8E-488E-B934-FDC4C7D2A385")
(node:2808) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening test.xcodeproj. Run CLI with --verbose flag for more details.
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project test.xcodeproj -configuration Debug -scheme test -destination id=06B32499-BA8E-488E-B934-FDC4C7D2A385

note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
warning: Capabilities for Signing & Capabilities may not function correctly because its entitlements use a placeholder team ID. To resolve this, select a development team in the test editor. (in target 'test' from project 'test')
ProcessProductPackaging "" /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test.app.xcent (in target 'test' from project 'test')
    cd /Users/alimran/workspace/reactnative/prod/test/ios
    

Entitlements:

{
    "com.apple.security.get-task-allow" = 1;
}


    builtin-productPackagingUtility -entitlements -format xml -o /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test.app.xcent

ProcessProductPackaging "" /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test.app-Simulated.xcent (in target 'test' from project 'test')
    cd /Users/alimran/workspace/reactnative/prod/test/ios
    

Entitlements:

{
    "application-identifier" = "FAKETEAMID.org.reactjs.native.example.test";
    "keychain-access-groups" =     (
        "FAKETEAMID.org.reactjs.native.example.test"
    );
}


    builtin-productPackagingUtility -entitlements -format xml -o /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test.app-Simulated.xcent

PhaseScriptExecution Start\ Packager /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Script-FD10A7F022414F080027D42C.sh (in target 'test' from project 'test')
    cd /Users/alimran/workspace/reactnative/prod/test/ios
    /bin/sh -c /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Script-FD10A7F022414F080027D42C.sh
/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Script-FD10A7F022414F080027D42C.sh: line 3: /Users/alimran/workspace/reactnative/prod/test/ios/../node_modules/react-native/scripts/.packager.env: Permission denied

CompileC /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/AppDelegate.o /Users/alimran/workspace/reactnative/prod/test/ios/test/AppDelegate.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'test' from project 'test')
    cd /Users/alimran/workspace/reactnative/prod/test/ios
    export LANG\=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -target x86_64-apple-ios10.0-simulator -fmessage-length\=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -std\=gnu99 -fobjc-arc -fmodules -gmodules -fmodules-cache-path\=/Users/alimran/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval\=86400 -fmodules-prune-after\=345600 -fbuild-session-file\=/Users/alimran/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror\=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror\=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror\=deprecated-objc-isa-usage -Wno-objc-interface-ivars -Werror\=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DDEBUG\=1 -DOBJC_OLD_DISPATCH_PROTOTYPES\=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.3.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wno-semicolon-before-method-body -fobjc-abi-version\=2 -fobjc-legacy-dispatch -index-store-path /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Index/DataStore -iquote /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-generated-files.hmap -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-own-target-headers.hmap -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-all-target-headers.hmap -iquote /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-project-headers.hmap -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Products/Debug-iphonesimulator/include -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources-normal/x86_64 -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources/x86_64 -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources -F/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Products/Debug-iphonesimulator -MMD -MT dependencies -MF /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/AppDelegate.d --serialize-diagnostics /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/AppDelegate.dia -c /Users/alimran/workspace/reactnative/prod/test/ios/test/AppDelegate.m -o /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/AppDelegate.o
In file included from /Users/alimran/workspace/reactnative/prod/test/ios/test/AppDelegate.m:1:
/Users/alimran/workspace/reactnative/prod/test/ios/test/AppDelegate.h:1:9: fatal error: 'React/RCTBridgeDelegate.h' file not found
#import <React/RCTBridgeDelegate.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

CompileC /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/main.o /Users/alimran/workspace/reactnative/prod/test/ios/test/main.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'test' from project 'test')
    cd /Users/alimran/workspace/reactnative/prod/test/ios
    export LANG\=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -target x86_64-apple-ios10.0-simulator -fmessage-length\=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -std\=gnu99 -fobjc-arc -fmodules -gmodules -fmodules-cache-path\=/Users/alimran/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval\=86400 -fmodules-prune-after\=345600 -fbuild-session-file\=/Users/alimran/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror\=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror\=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror\=deprecated-objc-isa-usage -Wno-objc-interface-ivars -Werror\=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DDEBUG\=1 -DOBJC_OLD_DISPATCH_PROTOTYPES\=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.3.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wno-semicolon-before-method-body -fobjc-abi-version\=2 -fobjc-legacy-dispatch -index-store-path /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Index/DataStore -iquote /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-generated-files.hmap -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-own-target-headers.hmap -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-all-target-headers.hmap -iquote /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-project-headers.hmap -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Products/Debug-iphonesimulator/include -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources-normal/x86_64 -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources/x86_64 -I/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources -F/Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Products/Debug-iphonesimulator -MMD -MT dependencies -MF /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/main.dia -c /Users/alimran/workspace/reactnative/prod/test/ios/test/main.m -o /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/main.o
In file included from /Users/alimran/workspace/reactnative/prod/test/ios/test/main.m:3:
/Users/alimran/workspace/reactnative/prod/test/ios/test/AppDelegate.h:1:9: fatal error: 'React/RCTBridgeDelegate.h' file not found
#import <React/RCTBridgeDelegate.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.


** BUILD FAILED **


The following build commands failed:
    CompileC /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/AppDelegate.o /Users/alimran/workspace/reactnative/prod/test/ios/test/AppDelegate.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    CompileC /Users/alimran/Library/Developer/Xcode/DerivedData/test-alolrygzfwbwxdfvdrglncimtovw/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/main.o /Users/alimran/workspace/reactnative/prod/test/ios/test/main.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(2 failures)

我希望有人能解决这个问题。谢谢 在此处输入图像描述

标签: reactjsxcodereact-nativenpm

解决方案


看起来有很多原因导致您收到这些错误。

  1. 首先你应该运行npx react-native run-ios(而不仅仅是react-native run-ios
  2. 如果您正在运行 XCode 项目,请在运行 react native 之前在您的 ios 目录中运行pod install
  3. 您的项目工作区似乎找不到您已安装的节点包。如果您确定已安装它们,请确保您从正确的目录(包含源文件夹的目录)运行命令
  4. 检查您的网络连接。您可能有代理配置或防火墙阻止您下载某些软件包。
  5. 看起来您的文件夹的读/写权限设置不正确,您可能需要对文件夹进行 chmod 以使其可读/可写

要获得更详细的帮助,您必须提供有关您的环境的信息:react-native 版本、cli 版本、文件夹结构和可能的 IDE(我在那里看到一个 eslint 错误......)。


推荐阅读