Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure: setHeaders throws exception #351

Closed
tobiasdiez opened this issue Jul 16, 2022 · 6 comments
Closed

azure: setHeaders throws exception #351

tobiasdiez opened this issue Jul 16, 2022 · 6 comments
Labels

Comments

@tobiasdiez
Copy link
Contributor

tobiasdiez commented Jul 16, 2022

Environment

  • Operating System: Linux
  • Node Version: v16.16.0
  • Nuxt Version: 3.0.0-rc.5
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: alias, nitro, ssr, meta, css, tailwindcss, modules, watch, runtimeConfig, serverHandlers, storybook, hooks
  • Runtime Modules: @nuxtjs/tailwindcss@5.1.3, @pinia/nuxt@0.3.0, ./modules/storybook, -runtime-compiler-module
  • Build Modules: -

Reproduction

I still have to find a way to reproduce this in a minimal enviroment.
For now you can run yarn dev:azure in https://github.com/JabRef/JabRefOnline.

Describe the bug

I get the following error when the app is deployed to azure (using nuxt):

[api] [2022-07-16T18:13:53.417Z] System.Private.CoreLib: Exception while executing function: Functions.functions. System.Private.CoreLib: Result: Failure
[api] [2022-07-16T18:13:53.417Z] Exception: Cannot set properties of undefined (setting 'content-type')
[api] [2022-07-16T18:13:53.417Z] Stack: TypeError: Cannot set properties of undefined (setting 'content-type')
[api] [2022-07-16T18:13:53.417Z]     at ServerResponse.setHeader (node:_http_outgoing:585:45)
[api] [2022-07-16T18:13:53.417Z]     at Object.errorhandler [as onError] (file:///workspace/JabRefOnline/.output/server/functions/chunks/nitro/azure.mjs:339:13)
[api] [2022-07-16T18:13:53.417Z]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[api] [2022-07-16T18:13:53.417Z]     at async nodeHandler (file:///workspace/JabRefOnline/.output/server/functions/node_modules/h3/dist/index.mjs:373:9)
[api] [2022-07-16T18:13:53.417Z]     at async Module.handle (file:///workspace/JabRefOnline/.output/server/functions/chunks/nitro/azure.mjs:1652:49).

The errorhandler is pointing to

event.res.setHeader('Content-Type', 'text/html')
, but I've yet to figure out why this is triggered in the first place (I think it actually triggered by another call to setHeader in a middleware).

Additional context

The line ServerResponse.setHeader (node:_http_outgoing:585:45) is pointing to https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L612. And indeed, this particular server response object contains only the kCapture symbol, but no other symbols (i.e. no kOutHeaders as normally).

Moreover, it might be related to unjs/h3#21.

Logs

No response

@tobiasdiez
Copy link
Contributor Author

A similar issue happens for IncomingMessage as well:

TypeError: Cannot read property 'pipes' of undefined     at IncomingMessage.Readable.unpipe (internal/streams/readable.js:821:13)     at unpipe (/home/site/wwwroot/functions/node_modules/unpipe/index.js:47:12)     at halt (/home/site/wwwroot/functions/node_modules/raw-body/index.js:129:3)     at invokeCallback (/home/site/wwwroot/functions/node_modules/raw-body/index.js:228:9)     at processTicksAndRejections (internal/process/task_queues.js:77:11)

with points to https://github.com/nodejs/node/blob/ba67fe66eb7777d5055c785be153374843fc647e/lib/internal/streams/readable.js#L856, i.e. _readableState does not exist.

@tobiasdiez
Copy link
Contributor Author

And similarly

TypeError: res._implicitHeader is not a function at writetop (/home/site/wwwroot/functions/node_modules/express-session/index.js:276:15) at ServerResponse.end (/home/site/wwwroot/functions/node_modules/express-session/index.js:343:16) at Immediate. (file:///home/site/wwwroot/functions/node_modules/h3/dist/index.mjs:138:17) at processImmediate (internal/timers.js:464:21)

@harish2704
Copy link

I too got stuck in this issue .
For me, it happened when I tried to mount an Express application in Nuxt3 application ( server/api , which internally uses nitro , h3, ofetch and unenv to serve server / API requests.

This issue happens because, ExpressJs and ofetch uses different implementations of ServerResponse class .

If my understanding is correct, this issue can be reproduced by mounting and running and ExpressJs application using h3.fromNodeMiddleware() function and calling that handler using ofetch from server

@tobiasdiez
Copy link
Contributor Author

As a workaround, you can overwrite the implementation of the offending methods with the node implementations. See eg the lines following https://github.com/JabRef/JabRefOnline/blob/036a7c3697713e9b998c708fa1f5e9ba4f0a0637/server/api/index.ts#L11

@gemyago
Copy link

gemyago commented Jan 7, 2024

I'm facing a similar issue and It is very likely related to server side rendering when fetch is performed on on server. It is working correctly when fetched client side. Very likely related to below issue as well: nuxt/nuxt#12720

@pi0
Copy link
Member

pi0 commented May 16, 2024

Hi. I'm not sure if it is something we should include to the core considering the cause backs to express incompatibility and patching native node http: is probably not best idea.

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants