react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Failed to start app in Android

Open am5a03 opened this issue 11 years ago • 8 comments

Hi, I've followed the guide to try to init AwesomeProject, however, it failed to start with the error

/Users/raymond/workspace/AwesomeProject/node_modules/react-native/packager/transformer.js:32
    filename,
            ^
SyntaxError: Unexpected token ,
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:411:25)
    at Object.Module._extensions..js (module.js:446:10)
    at Module.load (module.js:353:32)
    at Function.Module._load (module.js:308:12)
    at Module.require (module.js:363:17)
    at require (module.js:382:17)
    at process.<anonymous> (/Users/raymond/workspace/AwesomeProject/node_modules/react-native/node_modules/worker-farm/lib/child/index.js:45:34)
    at emitTwo (events.js:87:13)
    at process.emit (events.js:169:7)

When I check the file transformer.js

  const result = babel.transform(src, {
    retainLines: true,
    compact: true,
    comments: false,
    filename,
    whitelist: [
      // Keep in sync with packager/react-packager/.babelrc
      'es6.arrowFunctions',
      'es6.blockScoping',
      'es6.classes',
      'es6.destructuring',
      'es6.parameters',
      'es6.properties.computed',
      'es6.properties.shorthand',
      'es6.spread',
      'es6.templateLiterals',
      'es7.asyncFunctions',
      'es7.trailingFunctionCommas',
      'es7.objectRestSpread',
      'flow',
      'react',
      'react.displayName',
      'regenerator',
    ],
    plugins,
    sourceFileName: filename,
    sourceMaps: false,
    extra: options || {},
  });

It seems that this json is kinder broken, 'filename' and 'plugins' with nothing?

I'm not sure whether this is related to the error during my project init process:

> node-gyp rebuild

gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: 404 status code downloading tarball
gyp ERR! stack     at Request.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:246:14)
gyp ERR! stack     at emitOne (events.js:82:20)
gyp ERR! stack     at Request.emit (events.js:166:7)
gyp ERR! stack     at Request.onRequestResponse (/usr/local/lib/node_modules/npm/node_modules/request/request.js:1139:10)
gyp ERR! stack     at emitOne (events.js:77:13)
gyp ERR! stack     at ClientRequest.emit (events.js:166:7)
gyp ERR! stack     at HTTPParser.parserOnIncomingClient (_http_client.js:412:21)
stack     at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
gyp ERR! stack     at Socket.socketOnData (_http_client.js:302:20)
gyp ERR! stack     at emitOne (events.js:77:13)
gyp ERR! System Darwin 14.4.0
gyp ERR! command "/usr/local/Cellar/iojs/1.8.1/bin/iojs" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/raymond/workspace/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/bufferutil
gyp ERR! node -v v1.8.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm WARN optional dep failed, continuing [email protected]
npm WARN optional dep failed, continuing [email protected]

Thanks!

am5a03 avatar Sep 28 '15 05:09 am5a03

It seems that this json is kinder broken, 'filename' and 'plugins' with nothing?

It's the ES2015 object shorthand notation. Basically, when both the key and value have the same name, you can just write the name.

Have you tried removing your node_modules folder and running npm install again?

satya164 avatar Sep 28 '15 08:09 satya164

This is most likely caused by the error that occurred during your init. Please try:

$ rm -rf node_modules/
$ npm install

Hopefully this time there won't be an error. Looks like there was a 404 the first time which sounds like an issue with npmjs.com. If all goes well try running this again:

$ react-native run-android

And let us know if it works.

foghina avatar Sep 28 '15 11:09 foghina

If that doesn't work, try upgrading to Node 4 and installing via nvm, n, etc.

ide avatar Sep 28 '15 11:09 ide

If a request fails to npmjs.org, we should abort the install process and display an appropriate message instead of just continuing on.

astreet avatar Sep 28 '15 12:09 astreet

In iOS, I meet the same problem. Now, I try to remove the node_modules and Install again.

tokinonagare avatar Sep 29 '15 03:09 tokinonagare

@foghina Thanks, but no luck, my workaround right now is to explicitly setting filename and plugins to filename: filename plugins: plugins

am5a03 avatar Sep 29 '15 16:09 am5a03

Same issue on IOS

$ rm -rf node_modules/ $ npm install

gives no joy. I'll go with am5a02 for now

mschipperheyn avatar Oct 03 '15 17:10 mschipperheyn

Finally, I update & upgrade everything by:

brew update && upgrade

then rebuild the project, Now everything seems OK, perhaps this is the bug for some version.

tokinonagare avatar Oct 04 '15 03:10 tokinonagare