1

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

FROM ubuntu:trusty

MAINTAINER Developer team <[email protected]>

# 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"]

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

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

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 is used to run acceptance tests on release_app_1 container

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

2
  • What version of node is running that? It looks like it might not be recognising the object destructuring syntax.
    – david
    Oct 21, 2019 at 4:03
  • @david Query edited with package.json. I think it is node 4. I updated with belo changes.. testing Oct 21, 2019 at 6:22

1 Answer 1

2

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

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

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
4
  • In package.json, are the Verizon's of tools matching with node 6 Oct 21, 2019 at 6:10
  • I'm not sure, it's depend on your Node version on your development mode. It should be the same as this one so that everything will be consistent Oct 21, 2019 at 6:25
  • /bin/sh: 1: sudo: not found after your recommended changes FROM node:10.16 Oct 21, 2019 at 6:28
  • Sorry, I copied it from the question. Remove sudo should works. Answer updated. @overexchange Oct 21, 2019 at 6:31

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.