Error when trying to compile TypeScript project: Cannot find module 'undici' or its corresponding type declarations.
marcusmonteirodesouza opened this issue · 4 comments
Checklist
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
I'm getting the following errors when trying to compile a TypeScript project that has auth0
as a dependency:
node_modules/auth0/dist/cjs/lib/models.d.ts:2:28
- error TS2307: Cannot find module 'undici' or its corresponding type declarations.
import { Dispatcher } from 'undici';
~~~~~~~~
node_modules/auth0/dist/cjs/lib/models.d.ts:6:36 - error TS2552: Cannot find name 'RequestInfo'. Did you mean 'RequestInit'?
export type FetchAPI = (url: URL | RequestInfo, init?: RequestInit) => Promise;
~~~~~~~~~~~
node_modules/auth0/dist/cjs/lib/models.d.ts:60:19 - error TS2304: Cannot find name 'RequestCredentials'.
credentials?: RequestCredentials;
~~~~~~~~~~~~~~~~~~
node_modules/auth0/dist/cjs/lib/models.d.ts:99:16 - error TS2552: Cannot find name 'RequestInfo'. Did you mean 'RequestInit'?
url: URL | RequestInfo;
~~~~~~~~~~~
node_modules/auth0/dist/cjs/lib/models.d.ts:104:16 - error TS2552: Cannot find name 'RequestInfo'. Did you mean 'RequestInit'?
url: URL | RequestInfo;
~~~~~~~~~~~
node_modules/auth0/dist/cjs/lib/models.d.ts:109:16 - error TS2552: Cannot find name 'RequestInfo'. Did you mean 'RequestInit'?
url: URL | RequestInfo;
~~~~~~~~~~~
node_modules/auth0/dist/cjs/lib/models.d.ts:115:16 - error TS2552: Cannot find name 'RequestInfo'. Did you mean 'RequestInit'?
url: URL | RequestInfo;
~~~~~~~~~~~
Found 7 errors in the same file, starting at: node_modules/auth0/dist/cjs/lib/models.d.ts:2
Reproduction
- Create a TypeScript project using gts.
- Run
npm install auth0
. - Add the following line to the
index.ts
file:import * as auth0 from 'auth0';
- Run
npm run compile
or, alternatively,tsc
.
Additional context
Using gts to create a TypeScript project.
package.json
{
"name": "",
"version": "0.0.0",
"description": "",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"files": [
"build/src"
],
"license": "Apache-2.0",
"keywords": [],
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"lint": "gts lint",
"clean": "gts clean",
"compile": "tsc",
"fix": "gts fix",
"prepare": "npm run compile",
"pretest": "npm run compile",
"posttest": "npm run lint"
},
"devDependencies": {
"@types/node": "20.11.5",
"gts": "^5.3.0",
"typescript": "~5.4.3"
},
"dependencies": {
"auth0": "^4.4.0"
}
}
tsconfig.json
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
},
"include": [
"src//*.ts",
"test//*.ts"
]
}
node-auth0 version
^4.4.0
Node.js version
20.12.2
Experiencing this too (just the undici error)
node_modules/auth0/dist/cjs/lib/models.d.ts:2:28 - error TS2307: Cannot find module 'undici' or its corresponding type declarations.
same
Hey @marcusmonteirodesouza thanks for raising this, we’ll take a look.
Fix for this issue is released in https://www.npmjs.com/package/auth0/v/4.4.1