0

I'm getting this error "SyntaxError: Unexpected identifier" when I try to run 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"]

I start the container with a startup.sh shell script, this is where the error occurs:

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

Build and start the container:

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

Here are all my dependencies for my package.json file:

  "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"
  }

If I put the ace commands within the Dockerfile they seem to be OK.

Perhaps it is a linux configuration that I'm missing?

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

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

This is the docker build output with the ace commands inside, the problem seems to happen only when I run the 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

I was getting a similar error with @adonisjs/cli when trying to run the migration.

Evandro Pomatti
  • 13,341
  • 16
  • 97
  • 165

2 Answers2

1

I switched from the node image to ubuntu and configured the node installation myself to solve the problem.

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
`` 
Evandro Pomatti
  • 13,341
  • 16
  • 97
  • 165
0

A good solution could be to add the command on package.json, and call it on your docker environment. Some like:

Package.json:

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

On your .sh file:

...
npm run migrate:force
npm run serve
...
Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81