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

Cannot find module 'cbor-x/index-no-eval' or its corresponding type declarations. #513

Closed
mat813 opened this issue Jan 27, 2024 · 9 comments

Comments

@mat813
Copy link

mat813 commented Jan 27, 2024

Describe the issue

With 9.0.1, I get:

$ tsc
node_modules/@simplewebauthn/server/script/deps.d.ts(2,24): error TS2307: Cannot find module 'cbor-x/index-no-eval' or its corresponding type declarations.

Reproduction Steps

  1. Update to 9.0.1 on the server
  2. Try to build
  3. Get the error

Expected behavior

Not get a build error ?

Dependencies

  • OS: Linux
  • Browser: Node 21.6
  • Authenticator: n/a

SimpleWebAuthn Libraries

Server and types at 9.0.1

@MasterKale
Copy link
Owner

Hello @mat813, thanks for the report. This is related to #511, weird that an issue like this wasn't caught locally or in CI. I'll dig into this and report back.

Can you share your project's tsconfig.json?

@sualko
Copy link

sualko commented Feb 9, 2024

I have the same issue.

{
  "ts-node": {
    "files": true
  },
  "compilerOptions": {
    "module": "commonjs",
    "strict": true,
    "strictPropertyInitialization": false,
    "noImplicitOverride": true,
    "declaration": true,
    "removeComments": true,
    "resolveJsonModule": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6",
    "lib": ["dom", "dom.iterable", "esnext"],
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "exclude": ["node_modules", "dist", "tmp"],
  "include": ["src", "test"]
}

Not sure if this is related, but for some reason the default export no longer works for me. Instead of

import SimpleWebAuthnServer from '@simplewebauthn/server';

I have to use

import * as SimpleWebAuthnServer from '@simplewebauthn/server';

We are running Typescript in version 5.3.3.

I removed the node_modules folder and installed all dependencies again, but the package doesn't seam to be installed.

$ npm why cbor-x/index-no-eval
npm ERR! No dependencies found matching cbor-x/index-no-eval

@mat813
Copy link
Author

mat813 commented Feb 13, 2024

Here is my tsconfig.json :

{
  "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"
  ]
}

This still happens with @simplewebauthn/server@9.0.2 and @simplewebauthn/types@9.0.1.

@spendres
Copy link

Isn't @simplewebauthn/* installed in node_modules?
You may need to include "node_modules/@simplewebauthn/**/*.ts" since you excluded all of node_modules.

@MasterKale
Copy link
Owner

MasterKale commented Feb 13, 2024

Good eye @spendres, I'll bet that's it. cbor-x/no-index-eval is defined in the dependency's package.json here:

https://github.com/kriszyp/cbor-x/blob/0b5e8807622619c6a7a062f7e771478ecfd52f83/package.json#L59

If TypeScript can't see any types in node_modules/ (as evident in both tsconfig.json samples pasted above) I'm not surprised it's having issues transpiling.

My suggestion to fix that tsc error is to move "node_modules" from "exclude" to "include" instead and try again.

No, wait a minute, it's not that - exclude is about what gets transpiled. I get this same issue with the example project once I install @simplewebauthn/types (oops, gotta fix that) and then run npx tsc in there.

Investigating...

@MasterKale
Copy link
Owner

I created kriszyp/cbor-x#100 over in the cbor-x project because I discovered that locally duplicating their index.d.ts as index-no-eval.d.ts in my example project here's node_modules/cbor-x/ folder allowed tsc to understand types for cbor-x/index-no-eval. However I couldn't think of anything clever to do on the SimpleWebAuthn side of the house to get TypeScript to "alias" the index.d.ts type declarations for cbor-x/index-no-eval imports...

@MasterKale
Copy link
Owner

Okay, enough people are affected by this I think I'll have to revert #511 and figure something else out. The cbor-x project looks like it's being actively maintained, but there's evidence they may not have a lot of time to dedicate to addressing issues. I'll have to break Vercel's Edge runtime support for sake of restoring Node support, but my gut tells me there are more people in the latter group than the former.

@MasterKale
Copy link
Owner

I'm proposing fixing this issue by replacing use of cbor-x another library, tiny-cbor. @mat813 @sualko @mmv08 if you're feeling daring enough you can trying building and installing from the fix/513-cbor-x-type-issues branch to see if this fixes your issues. In my testing I think this is the solution, but extra confirmation couldn't hurt.

@MasterKale
Copy link
Owner

@mat813 @sualko @mmv08 This issue should be fixed in the newly published @simplewebauthn/server@9.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants