English 中文(简体)
新建 Nuxt3 应用程序正在丢弃与 Nitro 代理有关未定义的错误
原标题:New Nuxt3 app is throwing undefined error relating to Nitro proxy

I have been working on Nuxt2 for a while, and so I thought I would give 3 a try. After I finish the installation instructions found here: https://nuxt.com/docs/getting-started/installation I am getting the following error when I run a local server: ERROR [uncaughtException] proxyReq.appendHeader is not a function. It appears to be related to the nitro engine that Nuxt is using:

  at ProxyServer.<anonymous> (/C:/Users/cards/Documents/job-hunt/job-site/node_modules/nitropack/dist/chunks/server.mjs:329:18)
  at ProxyServer.emit (node:events:527:28)
  at ClientRequest.<anonymous> (/C:/Users/cards/Documents/job-hunt/job-site/node_modules/httpxy/dist/index.mjs:256:16)
  at ClientRequest.emit (node:events:527:28)
  at tickOnSocket (node:_http_client:764:7)
  at onSocketNT (node:_http_client:827:5)
  at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

我希望,如果我做了任何改变,我本可以打破某些错误,但这些错误从一开始就是正确的。 我做了一些研究,没有发现与此类似的问题。

守则中引起我争议的部分是:

proxy.proxy.on("proxyReq", (proxyReq, req) => {
    if (!proxyReq.hasHeader("x-forwarded-for")) {
      const address = req.socket.remoteAddress;
      if (address) {
        proxyReq.appendHeader("x-forwarded-for", address);
      }
    }
    if (!proxyReq.hasHeader("x-forwarded-port")) {
      const localPort = req?.socket?.localPort;
      if (localPort) {
        proxyReq.setHeader("x-forwarded-port", req.socket.localPort);
      }
    }
    if (!proxyReq.hasHeader("x-forwarded-Proto")) {
      const encrypted = req?.connection?.encrypted;
      proxyReq.setHeader("x-forwarded-proto", encrypted ? "https" : "http");
    }
  });

带有错误的准确行数 : proxyReq. append header ("x- toward- for", 地址);

我使用的是Nuxt版本:3.10.3和氮2.9.1。

问题回答

cnpm i [email protected]
This will solve the problem

您可能只是想要引爆您的软件包锁. json 并重新安装您的软件包。 有时可能会出现软件包不匹配, 导致错误 。

这对我管用

将节点.js 版本升级为 18 或 20 。 我自己的18.18.2 或 20.1.0 测试将不再报告错误 。

检查您的 Node.js 版本。 Nuxt 3 需要 node.js - v18. 0.0 或更新

快乐编码 :)





相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签