npm start命令给出errno 1的ELIFECYCLE错误

时间:2018-12-05 19:36:54

标签: node.js reactjs npm

我已经在Mac上使用sudo运行npm install,并且安装了0个漏洞。

启动npm时,出现错误代码ELIFECYCLE和errno 1。

我可以在Windows中运行相同文件而不会出错。

下面是运行日志

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@6.4.1
3 info using node@v11.3.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle tanaaz@0.1.0~prestart: tanaaz@0.1.0
6 info lifecycle tanaaz@0.1.0~start: tanaaz@0.1.0
7 verbose lifecycle tanaaz@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle tanaaz@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Files/Taannaz/Taannaz Web/tanaaz-master/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
9 verbose lifecycle tanaaz@0.1.0~start: CWD: /Files/Taannaz/Taannaz Web/tanaaz-master
10 silly lifecycle tanaaz@0.1.0~start: Args: [ '-c', 'node scripts/start.js' ]
11 silly lifecycle tanaaz@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle tanaaz@0.1.0~start: Failed to exec start script
13 verbose stack Error: tanaaz@0.1.0 start: `node scripts/start.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:978:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid tanaaz@0.1.0
15 verbose cwd /Files/Taannaz/Taannaz Web/tanaaz-master
16 verbose Darwin 18.2.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v11.3.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error tanaaz@0.1.0 start: `node scripts/start.js`
22 error Exit status 1
23 error Failed at the tanaaz@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

请提出必要的建议。

我也在下面分享了start.js中的代码行。再次,这在Windows 10中完全可以正常工作,并引发我在MacOS Mojave中提到的错误

'use strict';

// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'development';
process.env.NODE_ENV = 'development';

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
  throw err;
});

// Ensure environment variables are read.
require('../config/env');

const fs = require('fs');
const chalk = require('chalk');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const clearConsole = require('react-dev-utils/clearConsole');
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
const {
  choosePort,
  createCompiler,
  prepareProxy,
  prepareUrls,
} = require('react-dev-utils/WebpackDevServerUtils');
const openBrowser = require('react-dev-utils/openBrowser');
const paths = require('../config/paths');
const config = require('../config/webpack.config.dev');
const createDevServerConfig = require('../config/webpackDevServer.config');

const useYarn = fs.existsSync(paths.yarnLockFile);
const isInteractive = process.stdout.isTTY;

// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
  process.exit(1);
}

// Tools like Cloud9 rely on this.
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
const HOST = process.env.HOST || '0.0.0.0';

if (process.env.HOST) {
  console.log(
    chalk.cyan(
      `Attempting to bind to HOST environment variable: ${chalk.yellow(
        chalk.bold(process.env.HOST)
      )}`
    )
  );
  console.log(
    `If this was unintentional, check that you haven't mistakenly set it in your shell.`
  );
  console.log(`Learn more here: ${chalk.yellow('https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration')}`);
  console.log();
}

// We attempt to use the default port but if it is busy, we offer the user to
// run on a different port. `choosePort()` Promise resolves to the next free port.
choosePort(HOST, DEFAULT_PORT)
  .then(port => {
    if (port == null) {
      // We have not found a port.
      return;
    }
    const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
    const appName = require(paths.appPackageJson).name;
    const urls = prepareUrls(protocol, HOST, port);
    // Create a webpack compiler that is configured with custom messages.
    const compiler = createCompiler(webpack, config, appName, urls, useYarn);
    // Load proxy config
    const proxySetting = require(paths.appPackageJson).proxy;
    const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
    // Serve webpack assets generated by the compiler over a web sever.
    const serverConfig = createDevServerConfig(
      proxyConfig,
      urls.lanUrlForConfig
    );
    const devServer = new WebpackDevServer(compiler, serverConfig);
    // Launch WebpackDevServer.
    devServer.listen(port, HOST, err => {
      if (err) {
        return console.log(err);
      }
      if (isInteractive) {
        clearConsole();
      }
      console.log(chalk.cyan('Starting the development server...\n'));
      openBrowser(urls.localUrlForBrowser);
    });

    ['SIGINT', 'SIGTERM'].forEach(function(sig) {
      process.on(sig, function() {
        devServer.close();
        process.exit();
      });
    });
  })
  .catch(err => {
    if (err && err.message) {
      console.log(err.message);
    }
    process.exit(1);
  });

1 个答案:

答案 0 :(得分:0)

您看到以下内容

20 error code ELIFECYCLE
21 error errno 1
22 error tanaaz@0.1.0 start: `node scripts/start.js`
22 error Exit status 1

start.js到达process.exit(1)时。如果不希望这样做,则应调试代码并进行修复。