javascript icon indicating copy to clipboard operation
javascript copied to clipboard

backend-core: Cannot find type definition file for 'web'. ts(2688)

Open nomocas opened this issue 3 years ago • 7 comments

  • [x] Review the documentation: https://docs.clerk.dev/
  • [x] Search for existing issues: https://github.com/clerkinc/javascript/issues
  • [x] Go through package changelog files.
  • [ ] Provide the Frontend API key from your application dashboard.

Package + Version

  • [ ] @clerk/clerk-js
  • [ ] @clerk/clerk-react
  • [ ] @clerk/nextjs
  • [ ] @clerk/remix
  • [ ] @clerk/clerk-expo
  • [x] @clerk/backend-core
  • [x] @clerk/clerk-sdk-node
  • [ ] @clerk/edge
  • [ ] other:

Version:

@clerk/clerk-sdk-node: ^3.2.2
@clerk/backend-core: ^1.1.0
@clerk/types: ^2.2.0

Browser/OS

OSX 12.3 Nodejs 16.14.2 Typescript 4.6.3

Description

My backend project refuses to compile correctly.

tsconfig.json:

{
    "compilerOptions": {
        "lib": ["es2020", "dom"],
        "target": "es2020",
        "module": "CommonJS",
        "sourceMap": true,
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "baseUrl": "./src",
        "outDir": "./build",
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "esModuleInterop": true,
        "strictNullChecks": true
    },
    "files": ["..."],
    "include": ["src/**/*.ts"]
}

Compilation errors :

node_modules/@clerk/backend-core/dist/cjs/api/resources/Props.d.ts(1,23): error TS2688: Cannot find type definition file for 'web'.
node_modules/@clerk/backend-core/dist/cjs/Base.d.ts(1,23): error TS2688: Cannot find type definition file for 'web'.
node_modules/@clerk/backend-core/dist/cjs/util/types.d.ts(1,23): error TS2688: Cannot find type definition file for 'web'.

It comes from /// <reference types="web" />

What is weird is that I do not have this issue in my nextjs frontend, with the same @clerk/backend-core version (same typescript, nodejs and @clerk/clerk-sdk-node).

But even in my nextjs project: when I open Props.d.ts or Base.d.ts or types.d.ts: it says Cannot find type definition file for 'web'.ts(2688). But it compiles.

I tried several tsconfig changes. Nothing is working.

Any idea ?

Thanks.

nomocas avatar Mar 29 '22 13:03 nomocas

Ok fixed :

I should add @types/web explicitly in my project, and remove "dom" in my tsconfig./lib entry.

tsconfig.json:

{
    "compilerOptions": {
        "lib": ["es2020"],
        "target": "es2020",
        "module": "CommonJS",
        "sourceMap": true,
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "baseUrl": "./src",
        "outDir": "./build",
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "esModuleInterop": true,
        "strictNullChecks": true
    },
    "files": ["..."],
    "include": ["src/**/*.ts"]
}

In the clerk mono-repo: @types/web is only added to the root of the mono-repo. Not in backend-core nor in clerk-sdk-node.

I believe that it should be added to avoid same issue next time.

In the frontend (nextjs with @clerk/nextjs project with /api/... stuffs that use clerk-sdk-node), I do not find any @types/web (and yarn why @types/web find it neither). So it's not clear why it's compiling in my frontend.

But ok, it compiles in both.

Cheers.

nomocas avatar Mar 29 '22 14:03 nomocas

You saved our team some time today by posting your solution. Thank you!

trex-quo avatar Jun 14 '22 20:06 trex-quo

Thank you @nomocas!

mike-4040 avatar Jun 14 '22 21:06 mike-4040

@nomocas Why was this issue closed? It's definitely a problem with this package, and I'm not sure why @types/web is required for a backend package.

This is a bigger problem now because @types/node now conflicts @types/web over the AbortSignal declaration, necessitating skipLibCheck: true in tsconfig.json to compile:

node_modules/@types/web/index.d.ts:2007:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'AbortSignal' must be of type '{ new (): AbortSignal; prototype: AbortSignal; }', but here has type '{ new (): AbortSignal; prototype: AbortSignal; timeout(milliseconds: number): AbortSignal; }'.

2007 declare var AbortSignal: {
                 ~~~~~~~~~~~

  node_modules/@types/node/globals.d.ts:72:13
    72 declare var AbortSignal: {
                   ~~~~~~~~~~~
    'AbortSignal' was also declared here.


Found 1 error.

We should keep the issue open so that the maintainers can track/fix it.

no2chem avatar Aug 05 '22 06:08 no2chem

Hello @no2chem,

You are right, we should keep it open as it looks like nobody from clerk has seen it.

nomocas avatar Aug 05 '22 14:08 nomocas

We are working on a new version of clerk-sdk-node that is already available on our next branch/tag. Can you please send us replication steps so as to make sure that this issue is fixed?

SokratisVidros avatar Aug 05 '22 14:08 SokratisVidros

Hello @SokratisVidros,

After updating to @clerk/[email protected] (published yesterday), I still have several errors from missing dependencies.

To reproduce :

mkdir clerk-dependencies-error
cd clerk-dependencies-error
yarn init
yarn add @clerk/clerk-sdk-node
yarn add -D typescript tsc-watch

You should have this in your package.json:

{
  "name": "clerk-dependencies-error",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@clerk/clerk-sdk-node": "^4.1.0"
  },
  "devDependencies": {
    "tsc-watch": "^5.0.3",
    "typescript": "^4.7.4"
  }
}

Then add an index.ts on the root with this content:

import clerk from "@clerk/clerk-sdk-node";

clerk.users
  .getUserList({
    emailAddress: ["[email protected]"],
  })
  .then((user) => {
    console.log("user", user);
  });

And also a tsconfig.json on the root with this content:

{
  "compilerOptions": {
    "lib": ["es2020"],
    "target": "es2020",
    "module": "CommonJS",
    "sourceMap": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "outDir": "./build",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "esModuleInterop": true,
    "strictNullChecks": true
  },
  "include": ["**/*.ts"]
}

Then in your console trigger: yarn tsc-watch --onSuccess 'node ./build/index.js'

You should have 27 errors in your console.

To fix them : yarn add -D csstype @types/node-fetch @types/[email protected]

And again : yarn tsc-watch --onSuccess 'node ./build/index.js'

The compilation is then ok and of course, it says that it misses the CLERK_API_KEY env var (which is normal - if you provide one: it works).

You should notice that I've fixed the @types/web version to 0.0.55 (as the one defined on the root of your monorepo). If we simply do yarn add -D @types/web, it installs the 0.0.72, and then we still have an(other) error. (Maybe you could try to fix it in the same move... ;))

All errors are linked to the provided tsconfig (as without providing one, it compiles, because it targets ES5 by default). But the tsconfig is a valid one. So, IMHO, it should be linked to the target es2020 or something related.

I hope this will help.

Cheers.

nomocas avatar Aug 19 '22 17:08 nomocas

Hello everyone,

The latest release includes lots of changes related to how we're handling internal dependencies. I've tested using the provided project and tsconfig.json and I couldn't reproduce any of the above issues.

An important caveat to note however: the clerk-sdk-node depends on @clerk/types which does need the DOM lib so you will need to revert the tsconfig change and re-add "DOM" in the lib array. We already have plans to drop this dependency in a next major version update.

As always, we will be monitoring all these threads and any related issues such as:

  • https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1368
  • https://github.com/DefinitelyTyped/DefinitelyTyped/issues/60868
  • https://github.com/DefinitelyTyped/DefinitelyTyped/pull/61412 and make more adjustments if needed.

You can install the latest by running npm i @clerk/clerk-sdk-node@latest. Let me know if you hit any other issues, always happy to help.

@nomocas many thanks for the detailed explanation, it helped a lot :)

nikosdouvlis avatar Aug 29 '22 23:08 nikosdouvlis

Closing this one, but please feel free to ping us again if its needed :)

nikosdouvlis avatar Aug 31 '22 16:08 nikosdouvlis