0

I have a node.js application which I am trying to run in docker. Here is the package.json file snippet.

"main": "lib/server.js",
  "scripts": {
    "clean": "cross-env rm -rf dist",
    "build": "cross-env babel lib -d dist",
    "start": "npm run clean && npm run build && npm run serve",
    "serve": "node dist/index.js",
    "dev": "cross-env NODE_ENV=development nodemon lib/server.js --exec babel-node",
    "test": "echo \"Error: no test specified\" && exit 1",
    "lint": "eslint --ext .js lib/ scripts/ --ignore-pattern node_modules/"
  }

And here is the Dockerfile to build the image

#---- Base Node------
FROM node:10.15.1-alpine

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY package*.json ./

COPY lib ./lib

RUN npm install --only=production && npm run build

EXPOSE 4201

CMD ["npm", "run", "serve"]

I get the following error when I try to run the image. Here is the screenshot of the error.

enter image description here

The node and npm version are the same on my machine and the base image that I am using to build my image. When I run the same command locally in my machine it works Here is the exact command that I am running on my machine and it works.

npm install --only=production

npm run build

npm run serve

Am I doing something wrong here ? Any help is appreciated.

4
  • check your package.json dependency list, you might not have added express in it. Post full package.json file. Commented Feb 24, 2019 at 5:39
  • Are you sure Babel is available and transpiling successfully? Commented Feb 24, 2019 at 6:31
  • "babel-cli": "^6.26.0", "babel-polyfill": "^6.26.0", "express": "^4.16.4" Yes I have babel and express. How do I check if babel is transpiling successfully ? Commented Feb 24, 2019 at 14:50
  • Found it. I forgot to copy .babelrc in the Dockerfile to the workspace. It should have been this COPY .babelrc ./ . .babelrc is required for babel to transpile. Commented Feb 24, 2019 at 15:05

1 Answer 1

1

You are using ES6 imports

import x from package

In order to do that, you should have Babel package installed, otherwise it won't know how to import that file

Sign up to request clarification or add additional context in comments.

1 Comment

"babel-cli": "^6.26.0", "babel-polyfill": "^6.26.0", "express": "^4.16.4" Yes I have babel installed.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.