Cannot read properties of undefined (reading 'content-type') using express js
See original GitHub issueEnvironment
- Operating System:
Linux
- Node Version:
v16.10.0
- Nuxt Version:
3.0.0-27265876.3cd4494
- Package Manager:
yarn@1.22.17
- Bundler:
Vite
- User Config:
serverMiddleware
- Runtime Modules:
-
- Build Modules:
-
Describe the bug
serverMiddleware
doesn’t work with express.js (4.17.1)
and throws “Cannot read properties of undefined (reading 'content-type')
” error
Reproduction
Clone a repository with the bug and run it as dev server
$ git clone https://github.com/martiliones/nuxt-express-bug
$ cd nuxt-express-bug && yarn install
$ yarn dev
Open http://localhost:3000/projects/
in your browser
Additional context
I tested serverMiddleware
with h3 and it works just fine:
// api/index.js
import { createApp } from 'h3'
const app = createApp()
app.use('/projects', () => JSON.stringify([
{
name: 'asdsad',
type: ['asdsad', 'asdsad']
}
]))
Logs
Cannot read properties of undefined (reading 'content-type')
at ServerResponse.getHeader (node:_http_outgoing:597:24)
at ServerResponse.res.get (./node_modules/express/lib/response.js:789:15)
at ServerResponse.json (./node_modules/express/lib/response.js:263:13)
at file://./.nuxt/nitro/index.mjs:139:7
at Layer.handle [as handle_request] (./node_modules/express/lib/router/layer.js:95:5)
at next (./node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (./node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (./node_modules/express/lib/router/layer.js:95:5)
at ./node_modules/express/lib/router/index.js:281:22
at Function.process_params (./node_modules/express/lib/router/index.js:335:12)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:25 (10 by maintainers)
Top Results From Across the Web
TypeError: cannot read property of undefined (ExpressJS/POST)
I have a node js app in which I cannot print the input text from a form, using body-parser. My index.ejs: <form id="demo-2"...
Read more >Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError : Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an...
Read more >Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >5.x API - Express.js
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ), or an empty...
Read more >[Solved]-Why does the error occur "Cannot read properties of ...
... the error occur "Cannot read properties of undefined (reading 'title')"-node.js. ... Since this is a regular form post, it will using the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Using the full URL prevents Nitro from making a local call. So it’s a workaround with a performance cost.
Using the direct full URL eg
http://localhost:3000/api/whatever
Instead of
api/whatever
Worked for me …