Cannot use namespace 'ResponseLike' as a type.
Closed this issue · 18 comments
Describe the bug
When I'm running the project facing the error " Cannot find namespace 'CacheableRequest' "
node_modules/got/dist/source/core/options.d.ts:870:27 - error TS2503: Cannot find namespace 'CacheableRequest'.
870 get cache(): string | CacheableRequest.StorageAdapter | boolean | undefined;
~~~~~~~~~~~~~~~~
node_modules/got/dist/source/core/options.d.ts:871:31 - error TS2503: Cannot find namespace 'CacheableRequest'.
871 set cache(value: string | CacheableRequest.StorageAdapter | boolean | undefined);
~~~~~~~~~~~~~~~~
node_modules/got/dist/source/core/options.d.ts:1163:35 - error TS2503: Cannot find namespace 'CacheableRequest'.
1163 cache: string | boolean | CacheableRequest.StorageAdapter | undefined;
Even I am having the same issue during my build, please fix this
+1
Temporary workaround is to delete node_modules/@types/cacheable-request folder if you're not actually using this package. But of course, re-installs with npm i
+1
Hello - we are looking into this. Can you all tell us what version of got you are using?
@jaredwray 12.4.1 latest version
@types/cacheable-request@^6.0.2
got: version 12.4.1
Looks like its being included through package-json 8.1.0
It looks like @types/cacheable-request@^6.0.2 is the problem and we have not been maintaining this but will start looking for a fix on this. Again, sorry for the issues here and we are looking at this.
@Rehan-05 can you confirm it is this package?
Unsure if helpful, but I use typescript 4.8.2 and my tsconfig file is:
{ "compilerOptions": { "module": "es2022", "moduleResolution": "Node", "target": "ES2021", "sourceMap": true, "rootDir": "ts-src", "outDir": "build", "removeComments": true, "declaration": true, "esModuleInterop": true }, "include": ["ts-src/**/*.ts","ts-src/**/*.cts", "ts-src/**/*.mts"], "exclude": [ "node_modules" ] }
+1 Also facing this issue.
"version": "4.1.2",
tsconfig.json below:
{ "compilerOptions": { "target": "es6", "module": "commonjs", "allowJs": true, "esModuleInterop": true, "lib": ["dom", "es5", "es6", "es2017", "esnext.asynciterable", "es2018.promise"], "sourceMap": false, "outDir": "./dist", "moduleResolution": "node", "removeComments": true, "noImplicitAny": false, "strictNullChecks": false, "strictFunctionTypes": true, "noImplicitThis": true, "noUnusedLocals": false, "noUnusedParameters": false, "noImplicitReturns": false, "noFallthroughCasesInSwitch": true, "allowSyntheticDefaultImports": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "resolveJsonModule": true, "baseUrl": "src", "paths": { "@/*": ["./*"], "@helpers/*": ["helpers/*"], "@services/*": ["services/*"] } }, "exclude": ["node_modules", "dist", "mobile"], "include": ["src/**/*.ts", "test/**/*.ts"] }
Changing ResponseLike
to typeof ResponseLike
and ensuring noImplicitAny
and allowSyntheticDefaultImports
turned on in the ts.config
has cleared the issue for me.
@slwhitman - is this based on v9 of cacheable-response
? Would be good which one you were able to fix this on as there is a breaking change that is in the main
repo right now that are coming out. https://github.com/jaredwray/cacheable-request#breaking-changes-with-v930
I am new to typescript and I don't include any dependency in my package.json but still, I am getting errors while running the yarn tsc command here below my package.json and
{
"version": "${VERSION}",
"bin": "bin/index.js",
"devDependencies": {
"@types/node": "^18.7.16",
"pkg": "^5.8.0",
"typescript": "^4.8.2"
}
}
Errors:
../../../node_modules/@types/cacheable-request/index.d.ts:26:42 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
26 cb?: (response: ServerResponse | ResponseLike) => void
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:77:51 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
77 listener: (response: ServerResponse | ResponseLike) => void
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:81:69 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
81 on(event: 'response', listener: (response: ServerResponse | ResponseLike) => void): this;
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:84:71 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
84 once(event: 'response', listener: (response: ServerResponse | ResponseLike) => void): this;
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:89:51 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
89 listener: (response: ServerResponse | ResponseLike) => void
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:95:51 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
95 listener: (response: ServerResponse | ResponseLike) => void
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:104:51 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
104 listener: (response: ServerResponse | ResponseLike) => void
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:108:70 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
108 off(event: 'response', listener: (response: ServerResponse | ResponseLike) => void): this;
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:112:73 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
112 listeners(event: 'response'): Array<(response: ServerResponse | ResponseLike) => void>;
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:115:76 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
115 rawListeners(event: 'response'): Array<(response: ServerResponse | ResponseLike) => void>;
~~~~~~~~~~~~
../../../node_modules/@types/cacheable-request/index.d.ts:118:60 - error TS2709: Cannot use namespace 'ResponseLike' as a type.
118 emit(event: 'response', response: ServerResponse | ResponseLike): boolean;
~~~~~~~~~~~~
Found 11 errors in the same file, starting at: ../../../node_modules/@types/cacheable-request/index.d.ts:26
@bala-auvaria you're probably pulling it in through "pkg" package.
run 'npm ls @types/cacheable-request'
@slwhitman - is this based on v9 of
cacheable-response
? Would be good which one you were able to fix this on as there is a breaking change that is in themain
repo right now that are coming out. https://github.com/jaredwray/cacheable-request#breaking-changes-with-v930
I have v6.0.2
in my dependency but the PR was forked off your current code.
@jaredwray Please see sindresorhus/got#2129 (comment) for detailed analysis of the issue. There is no fault of your own here, the entirety of the issue belongs to got
.
@jaredwray
You were put in a bad situation and forced to bear some of result ofgot
new release. Your choices are simple:
- Do nothing (there is no fault in
cacheable-request
- Have
cacheable-request
depend onresponselike@3.0.0
(which should be simple and non-breaking you already depend on Node>=14)
@proton-ab thanks for the note and we are going to be looking at how to help on this more.
Hello All - they (got team) are waiting on an updated release based on this thread (sindresorhus/got#2129 (comment)). We have now published v10.0.0
which contains some major updates and a breaking change in how it is being used.
Here are the release notes: https://github.com/jaredwray/cacheable-request/releases/tag/v10.0.0
Also, here is an understanding of the new format to use:
import CacheableRequest from 'cacheable-request';
// Now You can do
const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();
const cacheReq = cacheableRequest('http://example.com', cb);
cacheReq.on('request', req => req.end());
// Future requests to 'example.com' will be returned from cache if still valid
// You pass in any other http.request API compatible method to be wrapped with cache support:
const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest();
const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest();
In addition any issues we are happy to work on with @sindresorhus or @szmarczak in anyway to get this fixed.
Going to close this issue/thread down and focus on the main one in got
: sindresorhus/got#2129 (comment)