MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.62k stars 137 forks source link

"Cannot import type declaration files" with 8.0.0+ #430

Closed mat813 closed 1 year ago

mat813 commented 1 year ago

Describe the issue

$ tsc
node_modules/@simplewebauthn/server/script/deps.d.ts:6:31 - error TS6137: Cannot import type declaration files. Consider importing 'debug' instead of '@types/debug'.

6 export type { Debugger } from '@types/debug';
                                ~~~~~~~~~~~~~~

Found 1 error in node_modules/@simplewebauthn/server/script/deps.d.ts:6

error Command failed with exit code 2.

Reproduction Steps

I tried downgrading TypeScript from 5.1.6 to 5.0.3 to 4.9.3 to 4.8.3 and all these versions emit this error.

Expected behavior

Well, to not break building my app.

Code Samples + WebAuthn Options and Responses

Not exactly sure, the only thing I am doing in my code is:

import { generateAuthenticationOptions, generateRegistrationOptions } from '@simplewebauthn/server';

Dependencies

SimpleWebAuthn Libraries

$  yarn list --depth=0 | grep @simplewebauthn
├─ @simplewebauthn/server@8.0.1
├─ @simplewebauthn/typescript-types@8.0.0
spendres commented 1 year ago

Those functions are now async in version ^8.0.0. Try awaiting those calls.

On Mon, Aug 28, 2023 at 7:31 AM Mathieu Arnold @.***> wrote:

Describe the issue

$ tsc @./server/script/deps.d.ts:6:31 - error TS6137: Cannot import type declaration files. Consider importing 'debug' instead of @./debug'.

6 export type { Debugger } from @.***/debug';



Found 1 error in ***@***.***/server/script/deps.d.ts:6

error Command failed with exit code 2.

Reproduction Steps

I tried downgrading TypeScript from 5.1.6 to 5.0.3 to 4.9.3 to 4.8.3 and
all these versions emit this error.
Expected behavior

Well, to not break building my app.
Code Samples + WebAuthn Options and Responses

Not exactly sure, the only thing I am doing in my code is:

import { generateAuthenticationOptions, generateRegistrationOptions } from ***@***.***/server';

Dependencies

   - *OS:* Linux 6.4.11
   - *Browser:* Node 20.5.1

SimpleWebAuthn Libraries

$  yarn list --depth=0 | grep @simplewebauthn
├─ @***@***.***
├─ @***@***.***

—
Reply to this email directly, view it on GitHub
<https://github.com/MasterKale/SimpleWebAuthn/issues/430>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEVLYGHKYYNZAY2VZY56WDXXR6PLANCNFSM6AAAAAA4BIXY5A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
mat813 commented 1 year ago

Yes, I did that. The only typescript error I get when building my code is the one I pasted above. As the error I get is not in my code, I gather my code is not the problem.

spendres commented 1 year ago

The 'export type' is in the code and 'declaration : true' is in the tsconfig.json file.

Are you running this in vscode? If so, try restarting the typescript server... https://stackoverflow.com/questions/60712323/how-to-export-types-in-a-typescript-npm-module

On Mon, Aug 28, 2023 at 8:53 AM Mathieu Arnold @.***> wrote:

Yes, I did that. The only typescript error I get when building my code is the one I pasted above.

— Reply to this email directly, view it on GitHub https://github.com/MasterKale/SimpleWebAuthn/issues/430#issuecomment-1695648510, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEVLYCPBAQZDPG6J5VNY4DXXSIFBANCNFSM6AAAAAA4BIXY5A . You are receiving this because you commented.Message ID: @.***>

MasterKale commented 1 year ago

@mat813 Can you please share your tsconfig.json? It might come in handy to recreate this on my end as I've yet to come across this before. I remember I used to import the Debugger type from debug instead of its @types/debug before v8.0.0, but sometime while working on v8.0.0 I changed it up to make something happy.

I'll investigate if you can provide me that tsconfig 🙂

mat813 commented 1 year ago

This is my tsconfig.json file:

{
  "compilerOptions": {
    "target": "es2021",
    "module": "commonjs",
    "esModuleInterop": true,
    "noImplicitAny": true,
    "outDir": "./built",
    "sourceMap": true,
    "inlineSources": true,
    "sourceRoot": "/",
    "noEmitHelpers": true,
    "importHelpers": true,
    "resolveJsonModule": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "strictNullChecks": true
  },
  "types": ["jest", "jest-extended"],
  "exclude": ["node_modules"],
  "include": [
    "apps/**/*.ts",
    "graphql/**/*.ts",
    "graphql/*.d.ts",
    "mailers/**/*.ts",
    "scripts/**/*.ts",
    "ecosystem.json"
  ]
}
MasterKale commented 1 year ago

I think I'm going to have to swap out the debug library I've been using, if I try to update the debug library and type import to make Node + TS happy...

// Attempt 1: Export like I would in Node, but include an empty export so that
// dnt includes @types/debug in the generated output
export { Debugger, default as debug } from 'https://esm.sh/debug@4.3.4';
export type {} from 'https://esm.sh/@types/debug@4.1.8';

// Attempt 2: Same as Attempt 1 but I also move the @types/debug
// declaration into the dnt build script so that it still gets included
export { Debugger, default as debug } from 'https://esm.sh/debug@4.3.4';

...then Deno errors out:

error: Uncaught SyntaxError: The requested module 'https://esm.sh/debug@4.3.4'
does not provide an export named 'Debugger'
export { Debugger, default as debug } from 'https://esm.sh/debug@4.3.4';
         ^

I have no idea right now how many people rely on the debugging output that right now is only used for understanding what MetadataService is up to. I intended to sprinkle more of the logging around but it was only ever really useful for this single service. I think right now I'm considering two options to resolve this particular issue:

  1. Find a Deno-friendly alternative that also supports Node
  2. Remove the debug logging output

I'll try and search a bit to find an alternative

MasterKale commented 1 year ago

@mat813 This should be fixed for now with @simplewebauthn/server@8.1.1 ✌️

mat813 commented 1 year ago

Yes, thank you.

I don't really understand how deno works (or what it actually is), but it seems that if the code it outputs is not compatible with typescript, it is probably a deno bug :(