Search code examples
node.jstypescriptauth0

Auth0 node package doesn't work unless I add "DOM" to my "lib" array in tsconfig. Why do I need to do this for purely backend service?


I have a nodejs backend service, and I want to use the auth0 management API to do some things like manually creating users.

Unfortunately, this library doesn't work unless I add "DOM" to my tsconfig.json.

Otherwise, I get the following errors:


node_modules/auth0/dist/cjs/auth/base-auth-api.d.ts(19,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/auth/base-auth-api.d.ts(21,102): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/auth/base-auth-api.d.ts(39,258): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/auth/base-auth-api.d.ts(39,305): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/errors.d.ts(7,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/errors.d.ts(9,60): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(5,36): error TS2304: Cannot find name 'RequestInfo'.
node_modules/auth0/dist/cjs/lib/models.d.ts(5,56): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/models.d.ts(5,80): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(15,28): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(55,30): error TS2304: Cannot find name 'FormData'.
node_modules/auth0/dist/cjs/lib/models.d.ts(59,19): error TS2304: Cannot find name 'RequestCredentials'.
node_modules/auth0/dist/cjs/lib/models.d.ts(65,15): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/models.d.ts(66,28): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/models.d.ts(69,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(75,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(78,35): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(79,43): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(82,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(86,26): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(87,30): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(91,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(94,40): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/lib/models.d.ts(95,30): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(98,16): error TS2304: Cannot find name 'RequestInfo'.
node_modules/auth0/dist/cjs/lib/models.d.ts(99,11): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/models.d.ts(103,16): error TS2304: Cannot find name 'RequestInfo'.
node_modules/auth0/dist/cjs/lib/models.d.ts(104,11): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/models.d.ts(108,16): error TS2304: Cannot find name 'RequestInfo'.
node_modules/auth0/dist/cjs/lib/models.d.ts(109,11): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/models.d.ts(110,15): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(114,16): error TS2304: Cannot find name 'RequestInfo'.
node_modules/auth0/dist/cjs/lib/models.d.ts(115,11): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/models.d.ts(117,16): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(121,46): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(121,65): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(122,46): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/models.d.ts(122,65): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/retry.d.ts(26,53): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/retry.d.ts(26,120): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/lib/runtime.d.ts(14,61): error TS2304: Cannot find name 'RequestInit'.
node_modules/auth0/dist/cjs/lib/runtime.d.ts(14,106): error TS2304: Cannot find name 'Response'.
node_modules/auth0/dist/cjs/management/management-client.d.ts(8,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/management/management-client.d.ts(11,94): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/userinfo/index.d.ts(34,14): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/userinfo/index.d.ts(36,102): error TS2304: Cannot find name 'Headers'.
node_modules/auth0/dist/cjs/userinfo/index.d.ts(38,46): error TS2304: Cannot find name 'Response'.

Is there some way I can avoid adding DOM to my tsconfig?


Solution

  • Unfortunately, the auth0 package depends on the Response interface, which is defined in the dom lib.

    You either have to add dom to the lib array, or specify skipLibCheck: true in compilerOptions. According to the TypeScript documentation:

    Rather than doing a full check of all d.ts files, TypeScript will type check the code you specifically refer to in your app’s source code.

    Check this answer for more details about the pros/cons of using skipLibCheck.