Internal server error: Cannot read property 'method' of undefined
Closed this issue · 2 comments
alok108 commented
For some strange reason I am getting this error
[vite] Internal server error: Cannot read property 'method' of undefined
at sendData (.../node_modules/.pnpm/vite-plugin-simple-json-server@0.6.0_vite@3.1.3/node_modules/vite-plugin-simple-json-server/dist/index.cjs:182:26)
at sendFileContent (...pnpm/vite-plugin-simple-json-server@0.6.0_vite@3.1.3/node_modules/vite-plugin-simple-json-server/dist/index.cjs:148:10)
at onGetAll (.../.pnpm/vite-plugin-simple-json-server@0.6.0_vite@3.1.3/node_modules/vite-plugin-simple-json-server/dist/index.cjs:650:12)
at handleJson (.../.pnpm/vite-plugin-simple-json-server@0.6.0_vite@3.1.3/node_modules/vite-plugin-simple-json-server/dist/index.cjs:802:20)
at runMiddleware (.../.pnpm/vite-plugin-simple-json-server@0.6.0_vite@3.1.3/node_modules/vite-plugin-simple-json-server/dist/index.cjs:1612:15)
at .../.pnpm/vite-plugin-simple-json-server@0.6.0_vite@3.1.3/node_modules/vite-plugin-simple-json-server/dist/index.cjs:1658:22
at call (.../.pnpm/vite@3.1.3/node_modules/vite/dist/node/chunks/dep-557f29e6.js:48413:7)
at next (.../.pnpm/vite@3.1.3/node_modules/vite/dist/node/chunks/dep-557f29e6.js:48357:5)
at Function.handle (.../.pnpm/vite@3.1.3/node_modules/vite/dist/node/chunks/dep-557f29e6.js:48360:3)
at Server.app (.../.pnpm/vite@3.1.3/node_modules/vite/dist/node/chunks/dep-557f29e6.js:48225:37)
at Server.emit (events.js:400:28)
at parserOnIncoming (_http_server.js:900:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:127:17) (x2)
I am able to get /api/home
which was configured like this
handlers: [
{
pattern: '/api/home',
method: 'GET',
handle: (req, res) => {
const data = {
a: 1,
b: 2,
c: 'c',
}
res.setHeader('content-type', 'application/json')
res.end(JSON.stringify(data))
},
},
],
But I am not able to get anything from json files in mock folder
alextim commented
Thanks for the issue.
Quite a strange error. It looks like the response object has lost its reference to the request somewhere. I couldn't reproduce it: examples runs locally and on Stackblitz.
Could you share more details about your environment? What is your Node version?
After some investigation.
This error occurs if the Node version is less than v15.7.0. Link to Node docs for response.req.
Simplest solution for now: update your Node ver up to 16 or 18.