首页 > 解决方案 > 使用 nuxtjs 部署到 Netlify 的错误

问题描述

使用nuxtjs开发的产品部署到Netlify的错误

在后端使用 Laravel 并在前端使用 Nuxtjs 部署开发时发生错误。我在本地环境开发的时候可以毫无问题地开发,但是在部署的时候出现了错误。

nuxt 2.15

节点:14.18.1

错误:请求失败,状态码 503

日志

3:20:15 PM: ❯ Version
3:20:15 PM:   @netlify/build 18.17.5
3:20:15 PM: ​
3:20:15 PM: ❯ Flags
3:20:15 PM:   baseRelDir: true
3:20:15 PM:   buildId: 6170092dc3e1251f30cb654e
3:20:15 PM:   deployId: 6170092dc3e1251f30cb6550
3:20:15 PM: ​
3:20:15 PM: ❯ Current directory
3:20:15 PM:   /opt/build/repo
3:20:15 PM: ​
3:20:15 PM: ❯ Config file
3:20:15 PM:   No config file was defined: using default values.
3:20:15 PM: ​
3:20:15 PM: ❯ Context
3:20:15 PM:   production
3:20:15 PM: ​
3:20:15 PM: ────────────────────────────────────────────────────────────────
3:20:15 PM:   1. Build command from Netlify app                             
3:20:15 PM: ────────────────────────────────────────────────────────────────
3:20:15 PM: ​
3:20:15 PM: $ npm run generate
3:20:15 PM: > ps4tek@1.0.0 gen /opt/build/repo
3:20:15 PM: > nuxt generate
[error] Request failed with status code 503
3:21:03 PM:   at createError (node_modules/axios/lib/core/createError.js:16:15)
3:21:03 PM:   at settle (node_modules/axios/lib/core/settle.js:17:12)
3:21:03 PM:   at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:269:11)
3:21:03 PM:   at IncomingMessage.emit (events.js:412:35)
3:21:03 PM:   at endReadableNT (internal/streams/readable.js:1334:12)
3:21:03 PM:   at processTicksAndRejections (internal/process/task_queues.js:82:21)
3:21:03 PM: [error]  /lms
3:21:03 PM: 
3:21:03 PM: RangeError: Maximum call stack size exceeded

3:21:03 PM: [error] Request failed with status code 503
3:21:03 PM:   at createError (node_modules/axios/lib/core/createError.js:16:15)
3:21:03 PM:   at settle (node_modules/axios/lib/core/settle.js:17:12)
3:21:03 PM:   at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:269:11)
3:21:03 PM:   at IncomingMessage.emit (events.js:412:35)
3:21:03 PM:   at endReadableNT (internal/streams/readable.js:1334:12)
3:21:03 PM:   at processTicksAndRejections (internal/process/task_queues.js:82:21)
3:21:05 PM: [fatal] Request failed with status code 503
3:21:05 PM:   at createError (node_modules/axios/lib/core/createError.js:16:15)
3:21:05 PM:   at settle (node_modules/axios/lib/core/settle.js:17:12)
3:21:05 PM:   at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:269:11)
3:21:05 PM:   at IncomingMessage.emit (events.js:412:35)
3:21:05 PM:   at endReadableNT (internal/streams/readable.js:1334:12)
3:21:05 PM:   at processTicksAndRejections (internal/process/task_queues.js:82:21)
3:21:05 PM: 
3:21:05 PM:    ╭────────────────────────────────────────────────╮
3:21:05 PM:    │                                                │
3:21:05 PM:    │   ✖ Nuxt Fatal Error                           │
3:21:05 PM:    │                                                │
3:21:05 PM:    │   Error: Request failed with status code 503   │
3:21:05 PM:    │                                                │
3:21:05 PM:    ╰────────────────────────────────────────────────╯
3:21:05 PM: 
3:21:05 PM: npm ERR! code ELIFECYCLE
3:21:05 PM: npm ERR! errno 1
3:21:05 PM: npm ERR! ps4tek@1.0.0 gen: `nuxt generate`
3:21:05 PM: npm ERR! Exit status 1
3:21:05 PM: npm ERR!
3:21:05 PM: npm ERR! Failed at the ps4tek@1.0.0 gen script.
3:21:05 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
3:21:05 PM: npm ERR! A complete log of this run can be found in:
3:21:05 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-10-20T12_21_05_489Z-debug.log
3:21:05 PM: ​
3:21:05 PM: ────────────────────────────────────────────────────────────────
3:21:05 PM:   "build.command" failed                                        
3:21:05 PM: ────────────────────────────────────────────────────────────────
3:21:05 PM: ​
3:21:05 PM:   Error message
3:21:05 PM:   Command failed with exit code 1: npm run gen
3:21:05 PM: ​
3:21:05 PM:   Error location
3:21:05 PM:   In Build command from Netlify app:
3:21:05 PM:   npm run gen
3:21:05 PM: ​
3:21:05 PM:   Resolved config
3:21:05 PM:   build:
3:21:05 PM:     command: npm run gen
3:21:05 PM:     commandOrigin: ui
3:21:05 PM:     environment:
3:21:05 PM:       - NODE_VERSION
3:21:05 PM:     publish: /opt/build/repo/dist
3:21:05 PM:     publishOrigin: ui
3:21:05 PM: Caching artifacts
3:21:05 PM: Started saving node modules
3:21:05 PM: Finished saving node modules
3:21:05 PM: Started saving build plugins
3:21:05 PM: Finished saving build plugins

nuxt.config.js

import axios from 'axios'
const credentials = require('./credentials.json');

export default  {

  target: "static",
  head: {
    title: 'xxxx',
    titleTemplate: ' %s | xxxxx',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    ],

    link: [
      { rel: 'preconnect', href: 'https://fonts.googleapis.com' },
      { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: true },
      { rel: 'preload', as: 'style', href: 'https://fonts.googleapis.com/css2?family=Tajawal:wght@200;300;400;500;800&display=swap' },
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
      { rel: 'stylesheet', href: '/css/bootstrap.min.css',async:true,media : "all" },
      { rel: 'stylesheet', href: '/css/main.min.css',async:true,media : "all" },
      { rel: 'stylesheet',  href: '/css/line/css/line-awesome.min.css' , media : "all" },
      { rel: 'stylesheet',async:true, href: 'https://fonts.googleapis.com/css2?family=Tajawal:wght@200;300;400;500;800&display=swap' },

    ],

  },
  plugins: [
    { src: 'plugins/flickity.js', ssr: false },
    { src: 'plugins/owl.js', ssr: false },
    { src: 'plugins/vue-phone-number-input.js', ssr: false },
    { src: 'plugins/vee-validate.js', ssr: false },
    { src: '~/plugins/guess', ssr: false },
    { src: '~/plugins/preview.client.js', ssr: false },


  ],
  components: true,
  buildModules: [
    '@nuxtjs/google-analytics',
    '~/modules/facebook-pixel',
    '@nuxtjs/web-vitals',
    '@nuxt/image',

  ],
 
  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    '@nuxt/image',
    '@nuxtjs/axios',
    '@nuxtjs/pwa',
    '@nuxt/content',
    '@nuxtjs/toast',
    '@nuxtjs/sitemap',
  
    [ "@nuxtjs/guess-module", { "GA": "xxxxxxx", "jwt": credentials }]
  ],
 

  axios: {
    baseURL: 'https://api.xxxxx.com', // Used as fallback if no runtime config is provided
    credentials: true,
  },
  generate: {
    fallback: true
  }
}

我怎么解决这个问题?

标签: nuxt.jsnetlify

解决方案


推荐阅读