Nuxt执行npm run build因nuxt-mongoose卡住,部署失败求助
Nuxt构建时nuxt-mongoose导致进程卡住的问题
开发环境下nuxt dev运行完全正常,但执行nuxt build命令时进程一直卡住无法完成,部署到Netlify平台时直接超时失败。已确认问题出在nuxt-mongoose模块——移除该模块后,构建命令可正常完成。
构建卡住时的输出
Total size: 52.8 MB (19.8 MB gzip) ✔ You can preview this build using node .output/server/index.mjs ├─ /__sitemap__/routes.json (0ms)
package.json
{ "name": "nuxt-app", "private": true, "scripts": { "build": "nuxt build", "dev": "nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare" }, "devDependencies": { "@nuxt/devtools": "latest", "@types/node": "^18", "nuxt": "^3.6.1", "nuxt-simple-robots": "^3.1.2", "nuxt-simple-sitemap": "^3.2.6", "sass": "^1.63.6" }, "dependencies": { "@nuxt/image": "^1.0.0-rc.1", "@nuxt/image-edge": "^1.0.0-rc.1-28143901.afe4120", "@nuxtjs/cloudinary": "^2.3.2", "dotenv": "^16.3.1", "nuxt-mongoose": "^0.0.9" } }
~/server/model/profile.js
import { defineMongooseModel } from '#nuxt/mongoose' export const ProfileSchema = defineMongooseModel({ name: 'profiles', schema: { name: String, desc: String, country: String, city: String, skills : [{ skill: String, level: String }], languages: [{ skill: String, level: String }] }, })
~/server/api/profile.js
export default eventHandler( async () => { try { return await ProfileSchema.findOne() } catch (e) { throw createError({ statusCode: 404, statusMessage: 'Page Not Found' }) } })
nuxt.config.ts
import 'dotenv/config' export default defineNuxtConfig({ devtools: { enabled: true }, app: { head: { charset: 'utf-8', viewport: 'width=device-width, initial-scale=1', htmlAttrs: { lang: 'en', }, } }, css: [ '~/assets/scss/main.scss', ], vite: { css: { preprocessorOptions: { scss: { additionalData: '@import "@/assets/scss/_variables";' } } } }, modules: [ '@nuxtjs/cloudinary', '@nuxt/image-edge', 'nuxt-simple-sitemap', 'nuxt-simple-robots', 'nuxt-mongoose', ], image: { cloudinary: { baseURL: `https://res.cloudinary.com/${process.env.CLOUDINARY_CLOUD_NAME}/image/upload/v1693287581` } }, nitro: { prerender: { routes: ['/portfolio', '/contact','/history'], }, }, site: { url: process.env.BASE_URL, }, mongoose: { uri: process.env.MONGODB_URI, options: {}, modelsDir: 'models', }, })
内容的提问来源于stack exchange,提问作者Jay
相关产品推荐
相关产品推荐

