首页 > 解决方案 > 安装包后 npm start 中断

问题描述

下面的原始问题

如果您现在使用,该错误似乎已修复create-react-native-app。它现在使用 react 0.55.2。


我们有一个正在使用 react native 构建的项目。

当我从网站运行这些命令时:

create-react-native-app AwesomeProject

我运行npm start它完美无缺。

如果我更改我的包(我添加了这一行):

"react-native-form-builder": "^1.0.15",

我跑npm install了,跑完之后npm start,我得到了这个错误:

C:\everforms>npm start

> everforms@0.1.0 start C:\everforms
> react-native-scripts start

11:57:29: Starting packager...
***ERROR STARTING PACKAGER***
No issue with doctor-npm-version
No issue with doctor-watchman-version
No issue with doctor-problem-checking-watchman-version
No issue with doctor-both-app-and-exp-json
No issue with doctor-schema-validation
No issue with doctor-validate-asset-fields
No issue with doctor-schema-validation-exception
No issue with doctor-unversioned
No issue with doctor-versions-endpoint-failed
No issue with doctor-invalid-sdk-version
No issue with doctor-node-modules-missing
No issue with doctor-react-native-not-installed

C:\everforms\node_modules\react-native\local-cli\cliEntry.js:30
import type {CommandT} from './commands';
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Module._compile (C:\everforms\node_modules\pirates\lib\index.js:91:24)
    at Module._extensions..js (module.js:663:10)
    at Object.newLoader [as .js] (C:\everforms\node_modules\pirates\lib\index.js:96:7)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
11:57:35: Error starting packager: Error: Metro Bundler process exited with code 1
    at ChildProcess.<anonymous> (C:\xdl@50.5.0\src\Project.js:1215:14)
    at Generator.next (<anonymous>)
    at step (C:\everforms\node_modules\xdl\build\Project.js:1768:191)
    at C:\everforms\node_modules\xdl\build\Project.js:1768:437
    at new Promise (<anonymous>)
    at ChildProcess.<anonymous> (C:\everforms\node_modules\xdl\build\Project.js:1768:99)
    at ChildProcess.packagerProcess.once (C:\xdl@50.5.0\src\Project.js:1213:5)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! everforms@0.1.0 start: `react-native-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the everforms@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\alber\AppData\Roaming\npm-cache\_logs\2018-07-05T09_57_35_135Z-debug.log

为什么会这样?

标签: node.jsreact-nativenpm

解决方案


此错误是 react-native 0.56 中影响 Windows 用户的新错误。要解决它,您可以使用另一个 react-native 版本创建一个项目:

react-native init --version="0.55.4" MyNewApp

您可以在此 GitHub 问题中查看更多信息。


推荐阅读