简体   繁体   中英

Unable to run node.js app through Docker container

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.

在此处输入图片说明

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM