简体   繁体   English

Nest js Docker 找不到模块 dist/main

[英]Nest js Docker Cannot find module dist/main

I am building a Nest.js App using Docker-compose.我正在使用 Docker-compose 构建一个 Nest.js 应用程序。 The problem is when I tried "docker-compose up prod" then it shows "Error: Cannot find module '/usr/src/app/dist/main."问题是当我尝试“docker-compose up prod”时,它显示“错误:找不到模块'/usr/src/app/dist/main。” Thus, I explored the files in the image of the prod, but I could find the dist folder.因此,我浏览了 prod 图像中的文件,但我可以找到 dist 文件夹。 Also, I run dist/main and it works.另外,我运行 dist/main 并且它有效。 However, I tried docker-compose up prod, it shows the above error.但是,我尝试了 docker-compose up prod,它显示了上述错误。 在此处输入图片说明

Moreover, when I tried "docker-compose up dev."此外,当我尝试“docker-compose up dev”时。 It works perfectly, making a dist folder to the host machine.它完美运行,为主机创建了一个 dist 文件夹。 The main difference between the dev and prod is the command that dev is using npm run start:dev, but prod is using npm run start:prod. dev 和 prod 的主要区别在于 dev 使用的是 npm run start:dev 命令,而 prod 使用的是 npm run start:prod。

This is My DockerFile这是我的 DockerFile


WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install rimraf
RUN npm install --only=development
COPY . .

RUN npm run build

FROM node:12.19.0-alpine3.9 as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
COPY --from=development /usr/src/app/dist ./dist
CMD ["node", "dist/main"]

This is my docker-compose.yaml这是我的 docker-compose.yaml


services:
    proxy:
        image: nginx:latest # 최신 버전의 Nginx 사용
        container_name: proxy # container 이름은 proxy
        ports:
            - '80:80' # 80번 포트를 host와 container 맵핑
        networks:
            - nestjs-network
        volumes:
            - ./proxy/nginx.conf:/etc/nginx/nginx.conf # nginx 설정 파일 volume 맵핑
        restart: 'unless-stopped' # 내부에서 에러로 인해 container가 죽을 경우 restart
        depends_on: 
            - prod
    dev:
        container_name: nestjs_api_dev
        image: nestjs-api-dev:1.0.0
        build:
            context: .
            target: development
            dockerfile: ./Dockerfile
        command: npm run start:dev #node dist/src/main #n
        ports:
            - 3001:3000
        networks:
            - nestjs-network
        volumes:
            - .:/usr/src/app
            - /usr/src/app/node_modules
        restart: unless-stopped
    prod:
        container_name: nestjs_api_prod
        image: nestjs-api-prod:1.0.0
        build:
            context: .
            target: production
            dockerfile: ./Dockerfile
        command: npm run start:prod
        # ports:
        #     - 3000:3000
        #     - 9229:9229
        expose:
            - '3000' # 다른 컨테이너에게 3000번 포트 open
        networks:
            - nestjs-network
        volumes:
            - .:/usr/src/app
            - /usr/src/app/node_modules
        restart: unless-stopped
networks:
    nestjs-network:```

Ok... I found the solution.好的...我找到了解决方案。 At the docker-compose.yaml, .:/usr/src/app should be removed from the volumes of the service "prod."在 docker-compose.yaml 中,.:/usr/src/app 应该从服务“prod”的卷中删除。 Since the "dist" folder does not exist in the local machine, if the current local directory is mounted, then it shows Not found error.由于本地机器中不存在“dist”文件夹,如果挂载了当前本地目录,则显示Not found错误。 Guess I should study volume much deeper.我想我应该更深入地研究音量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块./dist/es5 node.js - cannot find module ./dist/es5 node.js 找不到模块“/app/dist/bin/www.js” - Cannot find module '/app/dist/bin/www.js' 在Docker Parse Server中找不到模块'/parse/cloud/main.js' - Cannot find module '/parse/cloud/main.js' in Docker Parse Server 我如何解决错误:找不到模块'/node dist/api/server.js/dist/server.js - How do i resolve the Error: Cannot find module '/node dist/api/server.js/dist/server.js Yeoman:找不到模块“ ./dist/rx” - Yeoman: Cannot find module './dist/rx' 使用browserify gulp:找不到模块src / js / main.js - Gulp with browserify: Cannot find module src/js/main.js Gatsby - 错误:找不到模块 '..\node_modules\gatsby\dist\utils\babel-loader.js' - Gatsby - Error: Cannot find module '..\node_modules\gatsby\dist\utils\babel-loader.js' 启动快速应用程序时找不到模块“socket.io-client/dist/socket.io.js” - Cannot find module 'socket.io-client/dist/socket.io.js' when starting express application heroku /节点部署-找不到模块'app / dist / server / app.js' - heroku/node deployment - cannot find module 'app/dist/server/app.js' Angular + Electron - 找不到模块 main.js - Angular + Electron - Cannot find module main.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM