应用程序部署到 fly.io 时出错"/>
将 node.js 应用程序部署到 fly.io 时出错
第一次部署到 fly.io
我尝试使用
fly deploy
进行部署,但失败了,所以我遵循了本教程 ;t=18827
我尝试在本地使用 Docker 使用命令 fly deploy --local-only
部署它,但出现此错误:
=> ERROR [build 3/5] RUN npm install --production=false 3.3s
------
> [build 3/5] RUN npm install --production=false:
#10 0.938 npm WARN config production Use `--omit=dev` instead.
#10 3.216 npm ERR! code ERESOLVE
#10 3.226 npm ERR! ERESOLVE could not resolve
#10 3.226 npm ERR!
#10 3.227 npm ERR! While resolving: [email protected]
#10 3.227 npm ERR! Found: [email protected]
#10 3.228 npm ERR! node_modules/mongoose
#10 3.229 npm ERR! mongoose@"^7.0.3" from the root project
#10 3.229 npm ERR!
#10 3.230 npm ERR! Could not resolve dependency:
#10 3.231 npm ERR! peer mongoose@"~> 4.x" from [email protected]
#10 3.231 npm ERR! node_modules/mongoose-currency
#10 3.232 npm ERR! mongoose-currency@"^0.2.0" from the root project
#10 3.233 npm ERR!
#10 3.233 npm ERR! Conflicting peer dependency: [email protected]
#10 3.233 npm ERR! node_modules/mongoose
#10 3.234 npm ERR! peer mongoose@"~> 4.x" from [email protected]
#10 3.234 npm ERR! node_modules/mongoose-currency
#10 3.235 npm ERR! mongoose-currency@"^0.2.0" from the root project
#10 3.236 npm ERR!
#10 3.237 npm ERR! Fix the upstream dependency conflict, or retry
#10 3.238 npm ERR! this command with --force or --legacy-peer-deps
#10 3.238 npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
#10 3.238 npm ERR!
#10 3.238 npm ERR!
#10 3.238 npm ERR! For a full report see:
#10 3.238 npm ERR! /root/.npm/_logs/2023-04-28T09_06_28_271Z-eresolve-report.txt
#10 3.242
#10 3.242 npm ERR! A complete log of this run can be found in:
#10 3.242 npm ERR! /root/.npm/_logs/2023-04-28T09_06_28_271Z-debug-0.log
------
Error: failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c
npm install --production=false]: exit code: 1
貌似和mongoose没有关系,但我不确定到底是怎么回事。 这是我的 Dockerfile:
# syntax = docker/dockerfile:1
# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.15.0
FROM node:${NODE_VERSION}-slim as base
LABEL fly_launch_runtime="NodeJS"
# NodeJS app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV=production
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install -y python-is-python3 pkg-config build-essential
# Install node modules
COPY --link package.json package-lock.json .
RUN npm install --production=false
# Copy application code
COPY --link . .
# Remove development dependencies
RUN npm prune --production
# Final stage for app image
FROM base
# Copy built application
COPY --from=build /app /app
# Start the server by default, this can be overwritten at runtime
CMD [ "npm", "run", "start" ]
这是我的 package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"helmet": "^6.1.2",
"mongoose": "^7.0.3",
"mongoose-currency": "^0.2.0",
"morgan": "^1.10.0"
},
"devDependencies": {
"nodemon": "^2.0.22"
}
}
回答如下:
更多推荐
将 node.js 应用程序部署到 fly.io 时出错
发布评论