loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.06k forks source link

The key 'rest.http.request' is not bound to any value in context application #4572

Closed ghost closed 4 years ago

ghost commented 4 years ago

I installed the below mentioned version on loopback dependencies and getting the error attached in screen shot "@loopback/boot": "^1.4.3", "@loopback/context": "^1.20.1", "@loopback/core": "^1.8.4", "@loopback/extension-health": "^0.2.14", "@loopback/openapi-v3": "^1.6.4", "@loopback/repository": "^1.8.1", "@loopback/rest": "^1.16.2", "@loopback/rest-explorer": "^1.2.4", "@loopback/service-proxy": "^1.2.4",

Current Behavior

The moment the request hits application we get internal server error.The below error is thrown by loopback 4

Loopback

dougal83 commented 4 years ago

Please try suggested actions from #4570.

ghost commented 4 years ago

@dougal83 I did try that. It didn't help

jannyHou commented 4 years ago

@Ambay54 Do you think it's the same error as https://github.com/strongloop/loopback-next/issues/4570? If not could you submit a sample app we can use to reproduce the error?

dhmlau commented 4 years ago

@Ambay54, the latest version of @loopback/context is 2.1.1. Could you please update to the latest version and try? I noticed you're on 1.x. Here is some info on the breaking changes: https://github.com/strongloop/loopback-next/blob/master/packages/context/CHANGELOG.md#breaking-changes. Thanks.

achrinza commented 4 years ago

Closing due to inactivity. Feel free to open a new issue if the problem persists.

giano commented 4 years ago

Again with @loopback/cli@2.13.1, after lb4 update

├─┬ @loopback/core@2.9.5 │ └── @loopback/context@3.10.1 ├─┬ loopback4-helmet@1.1.0 │ └── @loopback/context@3.10.1 deduped └─┬ loopback4-notifications@1.0.0 └── @loopback/context@3.10.1 deduped

achrinza commented 4 years ago

Please delete node_modules and package-lock.json, then run npm start.

giano commented 4 years ago

No luck.

Unhandled error in GET /getLGX.aspx?u=XXX&p=XXX&c=XXX: 500 

ResolutionError: The key 'rest.http.request.context' is not bound to any value in context MyoxApplication-Rg4CeuOeRvWgF_tRDnIwbw-0 (context: MyoxApplication-Rg4CeuOeRvWgF_tRDnIwbw-0, binding: rest.http.request.context, resolutionPath: controllers.GetLgxController --> @GetLgxController.constructor[0] --> services.LoginService --> @LoginService.constructor[0] --> rest.sequence.actions.findRoute --> @FindRouteProvider.constructor[0])

    at MyoxApplication.getValueOrPromise (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/context.ts:810:13)
    at /Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolver.ts:159:20
    at /Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolution-session.ts:157:13
    at tryCatchFinally (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/value-promise.ts:222:14)
    at Object.tryWithFinally (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/value-promise.ts:197:10)
    at Function.runWithInjection (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolution-session.ts:156:12)
    at resolve (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolver.ts:143:38)
    at /Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolver.ts:246:12
    at Object.resolveList (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/value-promise.ts:169:28)
    at resolveInjectedArguments (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolver.ts:224:10)
    at Object.instantiateClass (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolver.ts:62:25)
    at /Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/binding.ts:721:33
    at Binding._getValue (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/binding.ts:604:14)
    at /Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/binding.ts:479:23
    at /Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/resolution-session.ts:122:13
    at tryCatchFinally (/Users/giano/Dropbox (Personale)/Programmazione/Nodejs/myox-next/myox/node_modules/@loopback/context/src/value-promise.ts:222:14)

As you can see the rest.http.request.context is actually bound to the controller

giano commented 4 years ago

Ok, solved, was actually a circular "import" loop in service classes that actually hanged build without any trace. Not related to new release or update.

But this can be an example of a misleading error trace that can cover a larger, unrelated, error. Consider close on my side.

malek0512 commented 4 years ago

Hello @giano, I encounter the same kind of issue.

Cannot start the application. { ResolutionError: The key 'rest.http.request.context' is not bound to any value in context BackAppApplication-zPIYBDp6TJOavlhaPSU68w-0 (context: BackAppApplication-zPIYBDp6TJOavlhaPSU68w-0, binding: rest.http.request.context, resolutionPath: lifeCycleObservers.BatchObserver --> @BatchObserver.constructor[0] --> services.ImportEngineService --> @ImportEngineService.constructor[2] --> rest.sequence --> @MySequence.constructor[0] --> rest.sequence.actions.findRoute --> @FindRouteProvider.constructor[0])

Any advice on how to reveal such a circular dependency ? (At first glance I don't see any..)

giano commented 4 years ago

Hi, my issue was importing from a class (example A.ts) not directly another class (B.ts) but the "folder" where both of the classes were in (and its index.ts that re-exported both classes).

This made the circular dependency less obvious.

Try importing prototypes or extended classes from specific files (not index.ts re-exports) and check if some classes refer each other (A imports B and B imports A, which is obviously a mistake, or, more subtle A imports B, B imports C and C imports A)

Hope it helps :)