首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在运行"npm“后收到npm错误: npm!代码ELIFECYCLE npm错误!errno 2

在运行"npm“后收到npm错误: npm!代码ELIFECYCLE npm错误!errno 2
EN

Stack Overflow用户
提问于 2018-11-10 20:55:27
回答 2查看 4.9K关注 0票数 3

在我的npm运行构建脚本执行后,我很难找到这个npm错误的底部。终端中的错误如下:

代码语言:javascript
复制
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! vincent-site@1.0.0 build: `webpack --mode production`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the vincent-site@1.0.0 build 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!     /Users/vincentcastelli/.npm/_logs/2018-11-10T20_27_41_388Z-debug.

不是很有描述性。在编写本报告时,我使用的是最新的npm版本(6.4.1)和最新的节点(11.1.0)。我也是用Babel 7和Webpack 4一起编写的。到目前为止,我已经尝试了几件事。

在使用npm/node的最新版本和旧版本时,我尝试了以下步骤:

  1. npm缓存干净
  2. 通过$ rm -rf node_modules文件夹删除node_modules
  3. npm安装

还在接收错误。

我的日志输出:

代码语言:javascript
复制
0 info it worked if it ends with ok
1 verbose cli [ '/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/node',
1 verbose cli   '/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@6.4.1
3 info using node@v11.1.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle vincent-site@1.0.0~prebuild: vincent-site@1.0.0
6 info lifecycle vincent-site@1.0.0~build: vincent-site@1.0.0
7 verbose lifecycle vincent-site@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle vincent-site@1.0.0~build: PATH: /Users/vincentcastelli/.nvm/versions/node/v11.1.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/vincentcastelli/Documents/02_Projects/vincent-site/node_modules/.bin:/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
9 verbose lifecycle vincent-site@1.0.0~build: CWD: /Users/vincentcastelli/Documents/02_Projects/vincent-site
10 silly lifecycle vincent-site@1.0.0~build: Args: [ '-c', 'webpack --mode production' ]
11 silly lifecycle vincent-site@1.0.0~build: Returned: code: 2  signal: null
12 info lifecycle vincent-site@1.0.0~build: Failed to exec build script
13 verbose stack Error: vincent-site@1.0.0 build: `webpack --mode production`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (/Users/vincentcastelli/.nvm/versions/node/v11.1.0/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> (/Users/vincentcastelli/.nvm/versions/node/v11.1.0/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:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:257:5)
14 verbose pkgid vincent-site@1.0.0
15 verbose cwd /Users/vincentcastelli/Documents/02_Projects/vincent-site
16 verbose Darwin 18.0.0
17 verbose argv "/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/node" "/Users/vincentcastelli/.nvm/versions/node/v11.1.0/bin/npm" "run" "build"
18 verbose node v11.1.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 2
22 error vincent-site@1.0.0 build: `webpack --mode production`
22 error Exit status 2
23 error Failed at the vincent-site@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]

我的package.json:

代码语言:javascript
复制
}
 "scripts": {
    "start": "node server.js",
    "build": "webpack --mode production"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "prop-types": "^15.6.1",
    "react": "^16.5.2",
    "react-dom": "^16.5.2",
    "react-router-dom": "^4.3.1"
  },
  "engines": {
    "node": "10.13.0"
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/react"
    ],
    "plugins": [
      "@babel/proposal-class-properties"
    ]
  },
  "eslintConfig": {
    "extends": "airbnb",
    "parser": "babel-eslint"
  },
  "devDependencies": {
    "@babel/core": "^7.1.5",
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/preset-env": "^7.1.5",
    "@babel/preset-react": "^7.0.0",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.4",
    "css-loader": "^1.0.1",
    "eslint": "^5.9.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-loader": "^2.1.1",
    "eslint-plugin-ejs": "0.0.2",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.1.2",
    "eslint-plugin-react": "^7.11.1",
    "file-loader": "^2.0.0",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.10.0",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.1",
    "webpack": "^4.25.1",
    "webpack-cli": "^3.1.2"
  }
}

我的webpack配置:

代码语言:javascript
复制
const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");

const distDir = path.join(__dirname, '/dist');
const srcDir = path.join(__dirname, '/src');


module.exports = {
  entry: `${srcDir}/index.jsx`,
  output: {
    path: `${distDir}`,
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /(node_modules|bower_components)/,
        use: ['babel-loader', 'eslint-loader'],
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader"
          }
        ]
      },
      {
        test: /\.scss$/,
            use: [
                "style-loader",
                "css-loader",
                "sass-loader"
            ]
      },
      {
        test: /\.(jpg|mp4|ogv|webm)$/,
        use: 'file-loader',
      },
    ],
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./dist/index.html",
      filename: "./index.html"
    })
  ],
  resolve: { extensions: ['*', '.js', '.jsx'] },
  devtool: 'cheap-eval-source-map',
};

我觉得这个问题源于一个包版本不兼容,但是孤立这个问题是很有挑战性的。提前感谢您的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-10 22:04:39

步骤1:$ npm缓存清理-强制

步骤2:删除node_modules文件夹

步骤3:删除包-锁. file文件

步骤4: npm安装

要重新启动,$ npm运行启动或npm运行构建

这对我有用。希望它对你有用。

票数 2
EN

Stack Overflow用户

发布于 2020-06-30 20:35:17

我发现我的CI/CD管道在一个虚拟机上运行,没有足够的内存,所以它失败了,并抛出了错误。

在运行该命令的地方检查您的内存

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53243326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档