NUXT 3生产模式抛出“未定义”。

发布于 2025-02-14 00:58:43 字数 1050 浏览 0 评论 0原文

我正在非服务器模式下运行NUXT 3应用程序ssr:false。它在开发模式下运行良好,但是一旦我通过npm run构建构建,然后通过node .Output/server/index.mjs启动服务器,就会出现使用错误500屏幕说进程未定义 没有调试信息,也没有控制台错误,也没有错误登录Heroku。

这是我的nuxt配置:

import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  css: ['vuetify/lib/styles/main.sass', 'mdi/css/materialdesignicons.min.css', '@/assets/sass/main.sass'],
  build: {
    transpile: ['vuetify'],
  },
  // vite: {
  //   define: {
  //     'process.env.DEBUG': false,
  //   },
  // },
  modules: [
    ['@nuxtjs/axios', { proxyHeaders: false }],
    '@pinia/nuxt'
  ],
  ssr: false // Disable server side rendering
})

如您所见,我还禁用了vite零件,因为这是我代码中Process甚至引用的唯一位置。

这是我看到的屏幕:

”在此处输入图像描述”

我在做什么错?

I am running a nuxt 3 app in non server mode ssr: false. It runs fine in development mode but as soon as I build the app via npm run build and then starting the server via node .output/server/index.mjs it comes up with a Error 500 screen saying process is not defined
There is no debug information, no console error and no error log on heroku either.

Here is my nuxt config:

import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  css: ['vuetify/lib/styles/main.sass', 'mdi/css/materialdesignicons.min.css', '@/assets/sass/main.sass'],
  build: {
    transpile: ['vuetify'],
  },
  // vite: {
  //   define: {
  //     'process.env.DEBUG': false,
  //   },
  // },
  modules: [
    ['@nuxtjs/axios', { proxyHeaders: false }],
    '@pinia/nuxt'
  ],
  ssr: false // Disable server side rendering
})

as you can see I also disabled the vite part as this is the only place in my code where process is even referenced.

This is the screen I see:

enter image description here

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光无声 2025-02-21 00:58:43

问题似乎在NUXT Axios模块上。
卸下模块并使用默认轴似乎使其正常工作。

Problem seems to be on the nuxt axios module.
Removing the module and using default axios it seems to make it work.

豆芽 2025-02-21 00:58:43

我删除了@nuxtjs/axios模块,只使用原始axios。有效。

I removed @nuxtjs/axios module and just use original axios. that works.

浅唱ヾ落雨殇 2025-02-21 00:58:43

当我用纱线添加进程时,我可以解决我的情况,然后添加为插件。

所以我这样做了:

yarn add process

然后在我的插件文件夹上创建一个process.ts文件:

插件/process.ts

import process from "process"

export default defineNuxtPlugin(nuxtApp => {
    globalThis.process = process
  })

< img src =“ https://i.sstatic.net/6znnh.png” alt =”输入图像描述在这里“>

并在我的nuxt.config.ts上添加,我添加了插件部分

import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
export default defineNuxtConfig({
  devtools: { enabled: true },
  plugins: [
    '~/plugins/process'
  ],
  build: {
    transpile: ['vuetify'],
  },
  modules: [
    (_options, nuxt) => {
      nuxt.hooks.hook('vite:extendConfig', (config) => {
        // @ts-expect-error
        config.plugins.push(vuetify({ autoImport: true }))
      })
    },
    '@pinia/nuxt'
    //...
  ],
  vite: {
    vue: {
      template: {
        transformAssetUrls,
      },
    },
  },
})

“输入图像描述在这里”

在该项目上,我使用的是NUXT 3 + VUE 3 + VUETIFY 3。

然后,可以在Vercel和Netilify中部署。

i solve my case when i add process with yarn, and then add as a plugin.

So i did this:

yarn add process

and then create a process.ts file on my plugins folder:

plugins/process.ts

import process from "process"

export default defineNuxtPlugin(nuxtApp => {
    globalThis.process = process
  })

enter image description here

and add on my nuxt.config.ts, i added the plugins section

import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
export default defineNuxtConfig({
  devtools: { enabled: true },
  plugins: [
    '~/plugins/process'
  ],
  build: {
    transpile: ['vuetify'],
  },
  modules: [
    (_options, nuxt) => {
      nuxt.hooks.hook('vite:extendConfig', (config) => {
        // @ts-expect-error
        config.plugins.push(vuetify({ autoImport: true }))
      })
    },
    '@pinia/nuxt'
    //...
  ],
  vite: {
    vue: {
      template: {
        transformAssetUrls,
      },
    },
  },
})

enter image description here

On that project i am using Nuxt 3 + Vue 3 + Vuetify 3.

And on that way, was possible to deploy in Vercel and Netilify.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文