Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 13 tasks
nomocas opened this issue Mar 29, 2022 · 9 comments · Fixed by #343
Closed
5 of 13 tasks

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

nomocas opened this issue Mar 29, 2022 · 9 comments · Fixed by #343
Assignees

Comments

@nomocas
Copy link

nomocas commented Mar 29, 2022

Package + Version

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/clerk-expo
  • @clerk/backend-core
  • @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
Copy link
Author

nomocas commented Mar 29, 2022

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 nomocas closed this as completed Mar 29, 2022
@trex-quo
Copy link

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

@mike-4040
Copy link

Thank you @nomocas!

@no2chem
Copy link

no2chem commented Aug 5, 2022

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

@nomocas
Copy link
Author

nomocas commented Aug 5, 2022

Hello @no2chem,

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

@nomocas nomocas reopened this Aug 5, 2022
@SokratisVidros
Copy link
Contributor

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?

@nomocas
Copy link
Author

nomocas commented Aug 19, 2022

Hello @SokratisVidros,

After updating to @clerk/clerk-sdk-node@4.1.0 (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: ["foo@bar.zoo"],
  })
  .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/web@0.0.55

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.

@nikosdouvlis nikosdouvlis self-assigned this Aug 25, 2022
@nikosdouvlis
Copy link
Member

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:

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
Copy link
Member

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants