How do I setup Dockerfile to run babel after install?

When running docker-compose up I keep getting a babel error when trying to build out my nodejs code since it is written in ES6 with imports and not const.

babel server.js -d dist && babel src -d dist/src

babel:
server.js does not exist

My directory structure is:

  • server.js

  • src

    • all other js files

How should I be setting up my Dockerfile, as I’m apparently not understanding file locations when creating the containers.

So far I have tried moving my build location to a dist folder instead of build but that was just a file rename. I also tried changing my COPY . to COPY server.js and that failed as well.

Dockerfile

FROM node:latest
WORKDIR /usr/src/app/api
COPY package.json /usr/src/app/api
RUN npm install
COPY . /usr/src/api
RUN npm run build
EXPOSE 4000
CMD npm run start

package.json

  "scripts": {
    "build": "babel server.js -d dist && babel src -d dist/src",
    "dev-start": "babel-watch server.js",
    "start": "npm run build && node dist/server.js"
  }

I expect the container to finish creating with the app built, and the actual result currently is a failed build and container failure.

Source: StackOverflow