在Windows上运行时,npm start无效

时间:2018-10-16 21:49:52

标签: node.js reactjs npm create-react-app npm-start

我正在使用create-react-app创建一个应用:create-react-app my-app 创建应用程序并执行npm start后,我得到此输出,但没有任何反应,该应用程序未启动:

my-app@0.1.0 start D:\Development\my-app
react-scripts start 

这是我使用npm start --verbose时得到的:

npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'start',
npm verb cli   '--verbose' ]
npm info using npm@6.4.1
npm info using node@v10.11.0
npm verb run-script [ 'prestart', 'start', 'poststart' ]
npm info lifecycle my-app@0.1.0~prestart: my-app@0.1.0
npm info lifecycle my-app@0.1.0~start: my-app@0.1.0

my-app@0.1.0 start D:\Development\my-app    
react-scripts start

npm verb lifecycle my-app@0.1.0~start: unsafe-perm in lifecycle true
npm verb lifecycle my-app@0.1.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\Development\my-app\node_modules\.bin;C:\Users\raguilarbecerra\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\Resources\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\dotnet;C:\Program Files (x86)\Java\jre1.8.0_144\bin;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn;C:\Program Files\Microsoft SQL Server\140\Tools\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Users\raguilarbecerra\Development\Nuget;'C;C:\Program Files\Git\Ruby\DevKit\4.7.2\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\ASUS\Bluetooth Software;C:\Program Files\ASUS\Bluetooth Software\syswow64;D:\Development\phantomjs-2.1.1-windows\bin;C:\Consul;C:\Program Files\Git\cmd;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE;C:\Users\raguilarbecerra\AppData\Local\Android\Sdk;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\Sennheiser\SoftphoneSDK;C:\Program Files\nodejs;C:\Ruby\2.2.6\bin;C:\Users\raguilarbecerra\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\raguilarbecerra\AppData\Local\Programs\Fiddler;C:\nvm;C:\Program Files\nodejs;C:\tools\cmder;C:\Users\raguilarbecerra\AppData\Local\GitHubDesktop\bin;C:\Users\raguilarbecerra\AppData\Local\hyper\app-2.0.0\resources\bin;C:\Users\raguilarbecerra\.dotnet\tools;C:\Users\raguilarbecerra\AppData\Roaming\Dashlane\6.1839.0.13410\bin\Firefox_Extension\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\raguilarbecerra\AppData\Roaming\Dashlane\6.1839.0.13410\ucrt;C:\Users\raguilarbecerra\AppData\Roaming\Dashlane\6.1839.0.13410\bin\Qt;C:\Users\raguilarbecerra\AppData\Roaming\Dashlane\6.1839.0.13410\ucrt;C:\Users\raguilarbecerra\AppData\Roaming\Dashlane\6.1839.0.13410\bin\Ssl;C:\Program Files\Oracle\VirtualBox;C:\Users\raguilarbecerra\AppData\Roaming\npm;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
npm verb lifecycle my-app@0.1.0~start: CWD: D:\Development\my-app
npm info lifecycle my-app@0.1.0~poststart: my-app@0.1.0
npm verb exit [ 0, true ]
npm timing npm Completed in 449ms
npm info ok

系统特征:

  • SO:Windows 10
  • 节点-v:v10.11.0
  • npm -v:6.4.1

package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.5.2",
    "react-dom": "^16.5.2",
    "react-scripts": "1.1.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

1 个答案:

答案 0 :(得分:0)

TL; DR -设置npm config set ignore-scripts true导致了我的问题,恢复了npm config set ignore-scripts false并重新安装了“ node_modules”,即删除了“ node_modules”并运行了“ npm install”,已解决即将死去的开发服务器的问题。

我遇到了完全相同的问题。运行--verbose之后,我得到了完全相同的日志。但是npm start不会启动开发服务器,并且会安静地终止。

我认为,如果未正确安装一个或多个软件包,则会出现此问题。当npm安装软件包时,系统会指示其安装位于config(即package.json文件)下的脚本,该脚本位于该软件包的标题“ postinstall”下。

如果未安装这些“安装后”脚本,则将遇到上述问题。

这是怎么发生在我身上的?我在npm配置中设置了一个标志,以防止设备安装“ postinstall”下列出的潜在恶意脚本。 npm config set ignore-scripts true。将其恢复为false可解决此问题。