Dockerfile-摩卡中意外的令牌错误 [英] Dockerfile - Unexpected token error in mocha

查看:139
本文介绍了Dockerfile-摩卡中意外的令牌错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是存储为图像标签somehub/someapp-specs的dockerfile:

Below is the dockerfile which is stored as image tag somehub/someapp-specs:

FROM ubuntu:trusty

MAINTAINER Developer team <developerteam@abc.com>

# Prevent dpkg source
ENV TERM=xterm-256color

# Set mirrors to ca
RUN sed -i "s/http:\/\/archive./http:\/\/ca.archive./g" /etc/apt/sources.list

# Install node.js
RUN apt-get update && \
    apt-get install curl -y && \
    curl -sL http://deb.nodesource.com/setup_4.x | sudo -E bash - && \
    apt-get install -y nodejs

COPY . /app
WORKDIR /app

# Install application dependencies
RUN npm install -g mocha && \
    npm install

# Set mocha test runner as entrypoint
ENTRYPOINT ["mocha"]


在docker-compose的以下抓取器中的test服务中使用的


which is used in test service in below snipper of docker-compose:

test:
  image: somehub/someapp-specs
  links:
    - nginx
  environment:
    URL: http://nginx:8080/todos
    JUNIT_REPORT_PATH: /reports/acceptance.xml
    JUNIT_REPORT_STACK: 1
  command: --reporter mocha-jenkins-reporter


启动mocha容器时出现错误:


that launched mocha container with error:

$ docker-compose up test
release_dbc_1 is up-to-date
Starting release_webroot_1 ... done
Creating release_app_1     ... done
Creating release_nginx_1   ... done
Creating release_test_1    ... done
Attaching to release_test_1
test_1     | /usr/lib/node_modules/mocha/bin/mocha:13
test_1     | const {deprecate, warn} = require('../lib/utils');
test_1     |       ^
test_1     | 
test_1     | SyntaxError: Unexpected token {
test_1     |     at exports.runInThisContext (vm.js:53:16)
test_1     |     at Module._compile (module.js:373:25)
test_1     |     at Object.Module._extensions..js (module.js:416:10)
test_1     |     at Module.load (module.js:343:32)
test_1     |     at Function.Module._load (module.js:300:12)
test_1     |     at Function.Module.runMain (module.js:441:10)
test_1     |     at startup (node.js:140:18)
test_1     |     at node.js:1043:3
release_test_1 exited with code 1


Dockerfile中的

COPY . /app指令正在复制具有以下版本的package.json:


COPY . /app instruction in Dockerfile is copying package.json with below versions:

{
  "name": "someappspecs",
  "version": "0.1.0",
  "description": "someapp acceptance tests",
  "main": "app.js",
  "scripts": {
    "test": "mocha"
  },
  "author": "xyz",
  "license": "ISC",
  "dependencies": {
    "bluebird": "^3.7.0",
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "mocha": "^6.2.1",
    "mocha-jenkins-reporter": "^0.4.2",
    "superagent": "^5.1.0",
    "superagent-promise": "^1.1.0"
  }
}


mocha用于在release_app_1容器


mocha is used to run acceptance tests on release_app_1 container

如何解决此意外的令牌错误?看起来与其他容器服务无关.

How to resolve this unexpected token error? looks unrelated with other container service.

推荐答案

这是因为Mocha需要节点> 6.0,而您的节点是4.x

That's because Mocha require node >6.0 but yours 4.x

从v6.0.0开始,Mocha需要Node.js v6.0.0或更高版本.

As of v6.0.0, Mocha requires Node.js v6.0.0 or newer.

尝试使用节点映像"升级您的节点:

Try to upgrade your node by using Node image:

FROM node:10.16

或者您可以像这样更新当前的dockerfile:

or you can update your current dockerfile like so:

RUN apt-get update && \
    apt-get install curl -y && \
    curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
    apt-get install -y nodejs

这篇关于Dockerfile-摩卡中意外的令牌错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆