ts-node: Property 'body' does not exist on type 'Request'.
See original GitHub issueProblem/Feature Request Summary
There seem to be something wrong with the typings of koa-body
. You sometimes get unexpected results when used together with ts-node:
/Users/m41n/source/repos/koabody/node_modules/ts-node/src/index.ts:261
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
src/controller.ts(5,39): error TS2339: Property 'body' does not exist on type 'Request'.
at createTSError (/Users/m41n/source/repos/koabody/node_modules/ts-node/src/index.ts:261:12)
at getOutput (/Users/m41n/source/repos/koabody/node_modules/ts-node/src/index.ts:367:40)
at Object.compile (/Users/m41n/source/repos/koabody/node_modules/ts-node/src/index.ts:557:11)
at Module.m._compile (/Users/m41n/source/repos/koabody/node_modules/ts-node/src/index.ts:439:43)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/m41n/source/repos/koabody/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
[nodemon] app crashed - waiting for file changes before starting...
Environment Information
koa-body: 4.0.4
koa: 2.5.2
node: 10.6.0
Steps to Reproduce
reproducible repo: https://github.com/jwldnr/koabody
-
install dependencies using yarn
->cd koabody && yarn
-
start nodemon
->yarn serve
… initial compile is ok (?). (no errors)
- open
src/controller.ts
and edit theconsole.log
line while nodemon is running
e.g. console.log("initial", email)
-> console.log("changed", email)
Error:
TSError: ⨯ Unable to compile TypeScript: src/controller.ts(5,39): error TS2339: Property 'body' does not exist on type 'Request'.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Property 'body' does not exist on type 'Request' - Stack Overflow
body -parser had been removed from express 4 into separate project, so there won't be any type definition about it. I use it...
Read more >ts-node: Property 'body' does not exist on type 'Request'. #109
Explicitly import koaBody in the file where 'request.body' is used can solve this problem. import koaBody from 'koa-body'; ...
Read more >Unable to compile TypeScript. Property 'user' does not exist on ...
Hello, I getting annoyed about typescript in my node api. I have written a jwtverify.ts. At first typescript has not accepted the req.user....
Read more >How to Improve Your Express Application | by Hoang Dinh
We can see, req.user will throw a TypeScript error — Property 'user' does not exist on type 'Request… . Then we have to...
Read more >How to fix 'Property does not exist on type Window in ...
Creating an index.d.ts file somewhere in our project. · Editing the file to define the types on the Window object. · (optional) adding...
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
I think its the defect of ts-node, similar problem occurs to me. For the same project:
tsc
will compile without errorts-node
will get: error TS2459: Type ‘Request’ has no property ‘body’ and no string index signatureI tried to add additional config to
tsconfig.json
, and then the error disappeared:It is because
tsc
could findnode_modules/koa-body/index.d.ts
, butts-node
can’t.ts-node
will only searchd.ts
files undernode_modules/@types
.@MarkHerhold I think you can move
index.d.ts
to@types/koa-body