简体   繁体   中英

React Native Android - init fails

I am attempting to create a new React Native project for Android. I followed the instructions here but when I attempt to init a new project using the command react-native init TestProject I get the following error

This will walk you through creating a new React Native project in D:\dev\projects\TestProject
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm ENOENT
    at exports._errnoException (util.js:837:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at doNTCallback2 (node.js:429:9)
    at process._tickCallback (node.js:343:17)
    at Function.Module.runMain (module.js:477:11)
    at startup (node.js:117:18)
    at node.js:951:3

Not sure where to get more information about the error. I have Node v4, NPM v2.14. Another thing to note is that the folder that gets created has a package.json that references node_modules/react-native/packager which does not exist in the current directory or the global scope.

Any suggestions would be greatly appreciated.

I try it too and I met the same problem. Then I found this issue: https://github.com/facebook/react-native/issues/2681

As said in the document : OS X - Only OS X is currently supported , and I'm using Windows which cause the issue.

I notice the path: D:\\dev\\projects\\TestProject\\events.js , so you are using Windows too.

It's a platform issue. Only OSX is supported see Issue and possible workarounds

react-native start

在cmd解决了我的问题

This is an old problem but got the similar issue while running react-native project in windows.

The following worked for me (in windows). Not sure whether it will work in every scenario or not. Just give it a try.

  1. Go to project location
  2. run command: react-native start .
  3. then in another cmd window run this command: react-native run-android .

Please comment below if doesn't work because I am still trying to figure out the reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM