gpt4 book ai didi

javascript - Dockerfile - Mocha 中出现意外的 token 错误

转载 作者:行者123 更新时间:2023-12-01 00:31:39 25 4
gpt4 key购买 nike

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

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 服务中使用:

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 容器时出现错误:

$ 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 中的/app 指令正在复制以下版本的 package.json:

{
"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 容器上运行验收测试

如何解决此意外 token 错误?看起来与其他容器服务无关。

最佳答案

那是因为 Mocha 需要 Node >6.0,但你的是 4.x

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

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

FROM node:10.16

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

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

关于javascript - Dockerfile - Mocha 中出现意外的 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58479409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com