当前位置: 首页 > 工具软件 > npm-consider > 使用案例 >

react-native开发:创建项目报错:Command `npm install --save --save-exact react-native` failed.

饶明亮
2023-12-01

现象:

D:\react-native>react-native init MyReactNativeApp
This will walk you through creating a new React Native project in D:\react-native\MyReactNativeApp
'yarn' �����ڲ����ⲿ���Ҳ���ǿ����еij���
�������ļ�
Installing react-native...
Consider installing yarn to make this faster: https://yarnpkg.com
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "--save-exact" "react-native"
npm ERR! node v6.3.1
npm ERR! npm  v3.10.3

npm ERR! shasum check failed for C:\Users\Juphome\AppData\Local\Temp\npm-13480-0dd1a05e\registry.npmjs.org\react-native\-\react-native-0.40.0.tgz
npm ERR! Expected: ca7b86a8e8fbc7653634ad47ca2ffd69fdf18ad5
npm ERR! Actual:   3ec5bf0d42d92d4fb48ef9bdefe0d8aa98dd55e8
npm ERR! From:     https://registry.npmjs.org/react-native/-/react-native-0.40.0.tgz
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     D:\react-native\MyReactNativeApp\npm-debug.log
{ Error: Command failed: npm install --save --save-exact react-native
    at checkExecSyncError (child_process.js:475:13)
    at execSync (child_process.js:515:13)
    at run (C:\Users\Juphome\AppData\Roaming\npm\node_modules\react-native-cli\index.js:294:5)
    at createProject (C:\Users\Juphome\AppData\Roaming\npm\node_modules\react-native-cli\index.js:249:3)
    at init (C:\Users\Juphome\AppData\Roaming\npm\node_modules\react-native-cli\index.js:200:5)
    at Object.<anonymous> (C:\Users\Juphome\AppData\Roaming\npm\node_modules\react-native-cli\index.js:153:7)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
  error: null,
  cmd: 'npm install --save --save-exact react-native',
  file: 'C:\\WINDOWS\\system32\\cmd.exe',
  args:
   [ 'C:\\WINDOWS\\system32\\cmd.exe',
     '/s',
     '/c',
     '"npm install --save --save-exact react-native"' ],
  options:
   { stdio: [ [Object], [Object], [Object] ],
     shell: true,
     windowsVerbatimArguments: true,
     file: 'C:\\WINDOWS\\system32\\cmd.exe',
     args:
      [ 'C:\\WINDOWS\\system32\\cmd.exe',
        '/s',
        '/c',
        '"npm install --save --save-exact react-native"' ],
     envPairs:
      [ '#envTSLOGSHELLEXT5452=253048896',
        '#envTSLOGsss5452=9998992',
        '#envTSLOGTSLOG5452=9999632',
        'ALLUSERSPROFILE=C:\\ProgramData',
        'APPDATA=C:\\Users\\Juphome\\AppData\\Roaming',
        'classpath=,;%JAVA_HOME%\\bin;%JAVA_HOME%\\jre\\bin',
        'CommonProgramFiles=C:\\Program Files\\Common Files',
        'CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files',
        'CommonProgramW6432=C:\\Program Files\\Common Files',
        'COMPUTERNAME=DESKTOP-PLDD7ET',
        'ComSpec=C:\\WINDOWS\\system32\\cmd.exe',
        'FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer',
        'FPS_BROWSER_USER_PROFILE_STRING=Default',
        'HOMEDRIVE=C:',
        'HOMEPATH=\\Users\\Juphome',
        'LOCALAPPDATA=C:\\Users\\Juphome\\AppData\\Local',
        'LOGONSERVER=\\\\DESKTOP-PLDD7ET',
        'NUMBER_OF_PROCESSORS=4',
        'OneDrive=C:\\Users\\Juphome\\OneDrive',
        'OS=Windows_NT',
        'Path=C:\\ProgramData\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;%JAVA_HOME%\\bin;%JAVA_HOME%\\jre\\bin;D:\\Android\\sdk\\tools;D:\\Program Files\\nodejs\\;D:\\Program Files (x86)\\Git\\cmd;D:\\Android\\sdk\\platform-tools;D:\\Program Files\\Ruby23-x64\\bin;C:\\Users\\Juphome\\AppData\\Roaming\\npm;C:\\Users\\Juphome\\AppData\\Local\\Microsoft\\WindowsApps',
        'PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JSE;.WSF;.WSH;.MSC;.RB;.RBW',
        'PROCESSOR_ARCHITECTURE=AMD64',
        'PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel',
        'PROCESSOR_LEVEL=6',
        'PROCESSOR_REVISION=4501',
        'ProgramData=C:\\ProgramData',
        'ProgramFiles=C:\\Program Files',
        'ProgramFiles(x86)=C:\\Program Files (x86)',
        'ProgramW6432=C:\\Program Files',
        'PROMPT=$P$G',
        'PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules',
        'PUBLIC=C:\\Users\\Public',
        'SDK_HOME=D:\\Android\\sdk',
        'SESSIONNAME=Console',
        'SystemDrive=C:',
        'SystemRoot=C:\\WINDOWS',
        'TEMP=C:\\Users\\Juphome\\AppData\\Local\\Temp',
        'TMP=C:\\Users\\Juphome\\AppData\\Local\\Temp',
        'USERDOMAIN=DESKTOP-PLDD7ET',
        'USERDOMAIN_ROAMINGPROFILE=DESKTOP-PLDD7ET',
        'USERNAME=Juphome',
        'USERPROFILE=C:\\Users\\Juphome',
        'VBOX_MSI_INSTALL_PATH=D:\\Program Files\\Oracle\\VirtualBox\\',
        'windir=C:\\WINDOWS' ] },
  envPairs:
   [ '#envTSLOGSHELLEXT5452=253048896',
     '#envTSLOGsss5452=9998992',
     '#envTSLOGTSLOG5452=9999632',
     'ALLUSERSPROFILE=C:\\ProgramData',
     'APPDATA=C:\\Users\\Juphome\\AppData\\Roaming',
     'classpath=,;%JAVA_HOME%\\bin;%JAVA_HOME%\\jre\\bin',
     'CommonProgramFiles=C:\\Program Files\\Common Files',
     'CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files',
     'CommonProgramW6432=C:\\Program Files\\Common Files',
     'COMPUTERNAME=DESKTOP-PLDD7ET',
     'ComSpec=C:\\WINDOWS\\system32\\cmd.exe',
     'FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer',
     'FPS_BROWSER_USER_PROFILE_STRING=Default',
     'HOMEDRIVE=C:',
     'HOMEPATH=\\Users\\Juphome',
     'LOCALAPPDATA=C:\\Users\\Juphome\\AppData\\Local',
     'LOGONSERVER=\\\\DESKTOP-PLDD7ET',
     'NUMBER_OF_PROCESSORS=4',
     'OneDrive=C:\\Users\\Juphome\\OneDrive',
     'OS=Windows_NT',
     'Path=C:\\ProgramData\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;%JAVA_HOME%\\bin;%JAVA_HOME%\\jre\\bin;D:\\Android\\sdk\\tools;D:\\Program Files\\nodejs\\;D:\\Program Files (x86)\\Git\\cmd;D:\\Android\\sdk\\platform-tools;D:\\Program Files\\Ruby23-x64\\bin;C:\\Users\\Juphome\\AppData\\Roaming\\npm;C:\\Users\\Juphome\\AppData\\Local\\Microsoft\\WindowsApps',
     'PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JSE;.WSF;.WSH;.MSC;.RB;.RBW',
     'PROCESSOR_ARCHITECTURE=AMD64',
     'PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel',
     'PROCESSOR_LEVEL=6',
     'PROCESSOR_REVISION=4501',
     'ProgramData=C:\\ProgramData',
     'ProgramFiles=C:\\Program Files',
     'ProgramFiles(x86)=C:\\Program Files (x86)',
     'ProgramW6432=C:\\Program Files',
     'PROMPT=$P$G',
     'PSModulePath=C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules',
     'PUBLIC=C:\\Users\\Public',
     'SDK_HOME=D:\\Android\\sdk',
     'SESSIONNAME=Console',
     'SystemDrive=C:',
     'SystemRoot=C:\\WINDOWS',
     'TEMP=C:\\Users\\Juphome\\AppData\\Local\\Temp',
     'TMP=C:\\Users\\Juphome\\AppData\\Local\\Temp',
     'USERDOMAIN=DESKTOP-PLDD7ET',
     'USERDOMAIN_ROAMINGPROFILE=DESKTOP-PLDD7ET',
     'USERNAME=Juphome',
     'USERPROFILE=C:\\Users\\Juphome',
     'VBOX_MSI_INSTALL_PATH=D:\\Program Files\\Oracle\\VirtualBox\\',
     'windir=C:\\WINDOWS' ],
  stderr: null,
  stdout: null,
  pid: 15376,
  output: [ null, null, null ],
  signal: null,
  status: 1 }
Command `npm install --save --save-exact react-native` failed.

解决:
D:\react-native>npm config set registry https://registry.npm.taobao.org

D:\react-native>npm config set disturl https://npm.taobao.org/dist

D:\react-native>react-native init MyReactNativeApp

然后耐心等待。。。
结果:
To run your app on iOS:
   react-native run-ios
   - or -
   Open ios\MyReactNativeApp.xcodeproj in Xcode
   Hit the Run button
To run your app on Android:
   Have an Android emulator running (quickest way to get started), or a device connected
   react-native run-android

希望你们也能成功,偶也


参考资料:


 类似资料: