NodeJS Auth0节点包不工作,除非我在tsconfig中将“DOM”添加到我的“lib”数组,为什么我需要这样做纯粹的后端服务?

bwleehnv  于 12个月前  发布在  Node.js
关注(0)|答案(1)|浏览(72)

我有一个nodejs后端服务,我想使用auth0管理API来做一些事情,比如手动创建用户。
不幸的是,除非我将"DOM"添加到tslog.json中,否则此库无法工作。
否则,我会得到以下错误:

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'.

有什么方法可以避免在tsconfig中添加DOM吗?

fivyi3re

fivyi3re1#

不幸的是,auth0包依赖于dom库中定义的Response接口。
您必须将dom添加到lib数组中,或者在compilerOptions中指定skipLibCheck: true。根据TypeScript文档:
TypeScript不会对所有d.ts文件进行全面检查,而是会键入检查您在应用源代码中特别引用的代码。
有关使用skipLibCheck的利弊的更多详细信息,请查看this answer

相关问题