首页 > 解决方案 > 中止(核心转储)npm ERR!代码 ELIFECYCLE(从节点 9 升级 -> 节点 10)

问题描述

我正在尝试构建一个包含我的 Vue.js 项目的 docker 映像,但是当我尝试从Node 9升级到Node 10时它失败并出现以下错误:

$ docker build -t frontend-image .
...
Step 10/10 : RUN npm run build
 ---> Running in a7b7f92e4615

> demo-vue@1.0.0 build /app
> node build/build.js

node[18]: ../src/node_file.cc:836:void node::fs::Stat(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `(argc) == (4)' failed.
 1: 0x9d8da0 node::Abort() [node]
 2: 0x9d8e27  [node]
 3: 0x9e5652  [node]
 4: 0xba3c19  [node]
 5: 0xba5a07 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
 6: 0x13726d9  [node]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! demo-vue@1.0.0 build: `node build/build.js`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the demo-vue@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!     /root/.npm/_logs/2019-10-23T19_00_49_014Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 134

下面的一些细节...

项目布局

frontend/
 -> build/
 -> config/
 -> src/
 -> static/
 -> test/
 -> build.sh
 -> Dockerfile
 -> package.json

前端/Dockerfile:

FROM node:10

# Works with node 9
#FROM node:9

RUN apt install curl

# make the 'app' folder the current working directory
RUN mkdir /app
WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .

# install simple http server for serving static content and project dependencies
RUN npm install -g http-server
RUN npm install


EXPOSE 8080
# PROD build
# build app for production with minification
RUN npm run build

前端/package.json(脚本部分):

  "scripts": {
    ...
    "build-server": "webpack --config build/webpack.server.conf.js && node src/server.js",
    "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
    "build": "node build/build.js && npm run build-server"
  },

前端/构建/build.js:

'use strict'
require('./check-versions')()

process.env.NODE_ENV = 'production'

const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.prod.conf')

const spinner = ora('building for production...')
spinner.start()

rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  if (err) throw err
  webpack(webpackConfig, (err, stats) => {
    spinner.stop()
    if (err) throw err
    process.stdout.write(stats.toString({
      colors: true,
      modules: false,
      children: false, // if you are using ts-loader, setting this to true will make tyescript errors show up during build
      chunks: false,
      chunkModules: false
    }) + '\n\n')

    if (stats.hasErrors()) {
      console.log(chalk.red('  Build failed with errors.\n'))
      process.exit(1)
    }

    console.log(chalk.cyan('  Build complete.\n'))
    console.log(chalk.yellow(
      '  Tip: built files are meant to be served over an HTTP server.\n' +
      '  Opening index.html over file:// won\'t work.\n'
    ))
  })
})

前端/构建/check-versions.js

'use strict'
const chalk = require('chalk')
const semver = require('semver')
const packageConfig = require('../package.json')
const shell = require('shelljs')

function exec (cmd) {
  return require('child_process').execSync(cmd).toString().trim()
}

const versionRequirements = [
  {
    name: 'node',
    currentVersion: semver.clean(process.version),
    versionRequirement: packageConfig.engines.node
  }
]

if (shell.which('npm')) {
  versionRequirements.push({
    name: 'npm',
    currentVersion: exec('npm --version'),
    versionRequirement: packageConfig.engines.npm
  })
}

module.exports = function () {
  const warnings = []

  for (let i = 0; i < versionRequirements.length; i++) {
    const mod = versionRequirements[i]

    if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
      warnings.push(mod.name + ': ' +
        chalk.red(mod.currentVersion) + ' should be ' +
        chalk.green(mod.versionRequirement)
      )
    }
  }

  if (warnings.length) {
    console.log('')
    console.log(chalk.yellow('To use this template, you must update following to modules:'))
    console.log()

    for (let i = 0; i < warnings.length; i++) {
      const warning = warnings[i]
      console.log('  ' + warning)
    }

    console.log()
    process.exit(1)
  }
}

查看上面的错误消息这部分:

   > node build/build.js

似乎是错误的原因,但以下文本并没有真正为我提供太多帮助来说明为什么会node build/build.js失败。

有任何想法吗?

标签: node.jsdockervue.js

解决方案


推荐阅读