Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Next.js Type error: Could not find a declaration file for module @scalar/openapi-parser #133

Closed
huypham50 opened this issue Jun 15, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@huypham50
Copy link

What happens?

Type error: Could not find a declaration file for module '@scalar/openapi-parser'. '/Users/johndoe/Desktop/repo/node_modules/@scalar/openapi-parser/dist/src/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/scalar__openapi-parser` if it exists or add a new declaration (.d.ts) file containing `declare module '@scalar/openapi-parser';`

> 1 | import { dereference } from "@scalar/openapi-parser";

What did you expect to happen?

Should have no type errors since package is written in Typescript (which is great!)

How can we reproduce the issue?

yarn add @scalar/openapi-parser

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "baseUrl": ".",
    "plugins": [
      {
        "name": "next"
      }
    ]
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    "types.d.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "ts-node": {
    "compilerOptions": {
      "module": "CommonJS"
    }
  }
}

next.config.js

module.exports = {
    reactStrictMode: true,
    swcMinify: true,
}

Swagger/OpenAPI Example

No response

@huypham50 huypham50 added the bug Something isn't working label Jun 15, 2024
@hanspagel
Copy link
Member

hanspagel commented Jun 15, 2024

What! Do you have the latest version? 0.7.1?

Latest version should have "types": "./dist/index.d.ts" not "types": "./dist/src/index.d.ts"

Anyway, I’m about to update the build process this week, I’ll make sure to fix this swiftly if it’s still in the latest version.

@huypham50
Copy link
Author

huypham50 commented Jun 15, 2024

Yep latest version 0.7.1 and the .d.ts is in the wrong place.

Screenshot 2024-06-15 at 7 16 44 AM

If I import { dereference } from "@scalar/openapi-parser/dist/src"; then the type errors go away but there's a compile error instead

Module not found: Package path ./dist/src is not exported from package /Users/johndoe/Desktop/code/repo/node_modules/@scalar/openapi-parser (see exports field in /Users/johndoe/Desktop/code/repo/node_modules/@scalar/openapi-parser/package.json)

@hanspagel
Copy link
Member

Oh man, I’ll fix that. Thanks for the great bug report!

@hanspagel
Copy link
Member

It’s more than just fixing the pass. Some type definition files land in random places. But #127 fixes it.

@huypham50
Copy link
Author

Thanks, I will test once change is live!

@hanspagel
Copy link
Member

Fixed already. ✌️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants