npm start出错



  • 在植入原生应用的时候,$ npm init
    $ npm install --save react-native
    $ curl -o .flowconfig https://raw.githubusercontent.com/facebook/react-native/master/.flowconfig
    这三行命令都OK
    执行npm start时出现
    0 info it worked if it ends with ok
    1 verbose cli [ 'E:\nodejs\node.exe',
    1 verbose cli 'E:\nodejs\node_modules\npm\bin\npm-cli.js',
    1 verbose cli 'start' ]
    2 info using npm@2.14.20
    3 info using node@v4.4.0
    4 verbose stack Error: Failed to parse json
    4 verbose stack Unexpected token 's' at 8:6
    4 verbose stack "start": "node_modules/react-native/packager/packager.sh"
    4 verbose stack ^
    4 verbose stack at parseError (E:\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:379:11)
    4 verbose stack at parseJson (E:\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:68:23)
    4 verbose stack at E:\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:48:5
    4 verbose stack at E:\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16
    4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
    5 verbose cwd F:\Test2
    6 error Windows_NT 6.1.7601
    7 error argv "E:\nodejs\node.exe" "E:\nodejs\node_modules\npm\bin\npm-cli.js" "start"
    8 error node v4.4.0
    9 error npm v2.14.20
    10 error file F:\Test2\package.json
    11 error code EJSONPARSE
    12 error Failed to parse json
    12 error Unexpected token 's' at 8:6
    12 error "start": "node_modules/react-native/packager/packager.sh"
    12 error ^
    13 error File: F:\Test2\package.json
    14 error Failed to parse package.json data.
    14 error package.json must be actual JSON, not just JavaScript.
    14 error
    14 error This is not a bug in npm.
    14 error Tell the package author to fix their package.json file. JSON.parse
    15 verbose exit [ 1, true ]
    0_1458806993272_123.jpg


  • administrators

    你的package.json格式不对,检查下引号啊逗号什么的



  • @sunnylqm

    0_1458809163326_123.jpg
    貌似是少了个逗号,添上了后出现这个鬼。。T_T
    我的package.json内容是init的时候生成的
    {
    "name": "test",
    "version": "1.0.0",
    "description": "test",
    "main": "index.android.js",
    "directories": {
    "start": "node_modules/react-native/packager/packager.sh",
    "test": "test"
    },
    "scripts": {
    "test": "test"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
    "react": "^0.14.7",
    "react-native": "^0.22.2"
    }
    }


  • administrators

    @名字一定要取好 说:

    start

    start是要放在scripts里的,怎么会放在directories下面



  • @sunnylqm
    我错鸟,改了

    {
    "name": "test",
    "version": "1.0.0",
    "description": "",
    "main": "index.android.js",
    "directories": {
    "test": "test"
    },
    "dependencies": {
    "react-native": "^0.22.2",
    "react": "^0.14.7"
    },
    "devDependencies": {},
    "scripts": {
    "start": "node_modules/react-native/packager/packager.sh",
    "test": "echo "Error: no test specified" && exit 1"
    },
    "author": "",
    "license": "ISC"
    }

    0_1458809771980_123.jpg 现在是这个鬼了。。


  • administrators

    @名字一定要取好
    换成

    "start": "node node_modules/react-native/local-cli/cli.js start"
    

    试试



  • @sunnylqm
    服务启动成功了,一运行就报
    com.facebook.react.bridge.JSExecutionException: ReferenceError: Can't find variable: __fbBatchedBridge (<unknown file>:1)
    的错 T_T



  • @sunnylqm
    unknown:React: Unable to download JS bundle
    03-24 18:37:40.220 23953-23982/com.example.administrator.test E/unknown:React: java.net.SocketTimeoutException: failed to connect to /192.168.0.123 (port 8081) after 5000ms
    请求超时是怎么回事啊?



  • @名字一定要取好 说:
    你是真机调试吗?要不是就把192.168.0.123 改localhost吧


登录后回复