0

我在尝试运行时收到此错误“SyntaxError: Unexpected identifier”node ace migration:run --force

/app/startup.sh:3
. node ace migration:run --force
       ^^^

SyntaxError: Unexpected identifier
    at wrapSafe (internal/modules/cjs/loader.js:1054:16)
    at Module._compile (internal/modules/cjs/loader.js:1102:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

Dockerfile

FROM node:12 AS bizi
COPY . /app
WORKDIR /app
RUN ["npm", "i"]

我使用 shell 脚本启动容器startup.sh,这是发生错误的地方:

#!/bin/sh
cd /app
node ace migration:run --force
adonis serve

构建并启动容器:

docker build -t myapp .
docker run -p 8080:80 myapp startup.sh

这是我的package.json文件的所有依赖项:

  "dependencies": {
    "@adonisjs/ace": "^5.0.8",
    "@adonisjs/ally": "^2.1.3",
    "@adonisjs/auth": "^3.0.7",
    "@adonisjs/bodyparser": "^2.0.5",
    "@adonisjs/cors": "^1.0.7",
    "@adonisjs/fold": "^4.0.9",
    "@adonisjs/framework": "^5.0.13",
    "@adonisjs/generic-exceptions": "^3.0.1",
    "@adonisjs/ignitor": "^2.0.8",
    "@adonisjs/lucid": "^6.1.3",
    "@adonisjs/mail": "^3.0.9",
    "@adonisjs/validator": "^5.0.6",
    "@azure/service-bus": "^1.1.7",
    "axios": "^0.19.0",
    "cpf-check": "^3.0.0",
    "firebase-admin": "^8.3.0",
    "moment": "^2.24.0",
    "order-id": "^1.1.0",
    "pg": "^7.12.0",
    "require-dir": "^1.2.0",
    "uuid": "^3.3.2"
  }

如果我将 ace 命令放在 Dockerfile 中,它们似乎没问题。

也许这是我缺少的 linux 配置?

FROM node:12 AS bizi
COPY . /app
WORKDIR /app
RUN ["npm", "i"]

# Added ace commands
RUN node ace
RUN node ace migration:run --force

这是里面带有 ace 命令的 docker build 输出,问题似乎只有在我运行 shell 时才会发生。

Step 5/6 : RUN node ace --help
 ---> Running in f9bd319e8031
Usage:
  command [arguments] [options]

Global Options:
  --env                  Set NODE_ENV before running the commands
  --no-ansi              Disable colored output
  --version              output the version number

Available Commands:
  seed                   Seed database using seed files
 connect
  connect:fridge-queue   Tell something helpful about this command
 make
  make:validator         Make route validator
 migration
  migration:refresh      Refresh migrations by performing rollback and then running from start
  migration:reset        Rollback migration to the first batch
  migration:rollback     Rollback migration to latest batch or to a specific batch number
  migration:run          Run all pending migrations
  migration:status       Check migrations current status

@adonisjs/cli尝试运行迁移时,我遇到了类似的错误。

4

2 回答 2

1

我从node镜像切换到ubuntu自己配置节点安装来解决问题。

FROM ubuntu:latest
USER root

RUN apt-get update
RUN apt -y upgrade
RUN apt-get -y install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_12.x  | bash -
RUN apt-get -y install nodejs

COPY . /app
WORKDIR /app
RUN npm i -g @adonisjs/cli
RUN npm i
`` 
于 2020-06-01T02:05:19.057 回答
0

一个好的解决方案是在 package.json 中添加命令,并在您的 docker 环境中调用它。一些喜欢:

包.json:

...
"scripts": {
  "start": "node server.js",
  "test": "node ace test",
  "serve": "adonis serve"
  "migrate:force": "ace migration:run --force"
},
...

在您的 .sh 文件上:

...
npm run migrate:force
npm run serve
...
于 2020-11-05T13:11:28.570 回答