Docker撰写:npm ERR!缺少脚本:构建

时间:2020-03-17 18:18:03

标签: node.js docker

你好,我不知道在尝试将docker compose与postgress配合使用时错在哪里

docker compose yml:

version: "3.7"
services:
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: emasa
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    web:
      image: emasapg
      depends_on:
        - dbs
      ports:
        - "4000:4000"

dockerfile

FROM node as builder
WORKDIR usr/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build


FROM node
WORKDIR usr/app
COPY package*.json ./
RUN npm install --production

COPY --from=builder /usr/app/dist ./dist

COPY ormconfig.docker.json ./ormconfig.json
COPY .env . 

expose 4000
CMD node dist/src/index.js

我的package.json:

{
  "name": "back-end",
  "version": "0.0.1",
  "description": "Awesome project developed with TypeORM.",
  "devDependencies": {
    "@types/express": "^4.17.3",
    "@types/graphql": "^14.5.0",
    "@types/node": "^13.9.1",
    "ts-node": "8.6.2",
    "typescript": "3.3.3333"
  },
  "dependencies": {
    "apollo-server-express": "^2.11.0",
    "express": "^4.17.1",
    "graphql": "^14.6.0",
    "pg": "^7.3.0",
    "reflect-metadata": "^0.1.13",
    "typeorm": "0.2.24"
  },
  "scripts": {
    "start": "ts-node src/index.ts"
  }
}

错误:

npm ERR!缺少脚本:构建

我的文件结构:

enter image description here

错误开始于此行:

第6行:RUN npm run build

编辑:忘记将package.json添加到问题中

1 个答案:

答案 0 :(得分:2)

基本上是抱怨缺少构建脚本,它试图运行该脚本,但是您的package.json中却缺少它!

我认为您应该尝试更新package.json文件并添加构建脚本:

{
  "name": "back-end",
  "version": "0.0.1",
  "description": "Awesome project developed with TypeORM.",
  "devDependencies": {
    "@types/express": "^4.17.3",
    "@types/graphql": "^14.5.0",
    "@types/node": "^13.9.1",
    "ts-node": "8.6.2",
    "typescript": "3.3.3333"
  },
  "dependencies": {
    "apollo-server-express": "^2.11.0",
    "express": "^4.17.1",
    "graphql": "^14.6.0",
    "pg": "^7.3.0",
    "reflect-metadata": "^0.1.13",
    "typeorm": "0.2.24"
  },
  "scripts": {
    "start": "ts-node src/index.ts",
    "build": ""  // your build script goes here, "tsc" should be fine
  }
}