scalar / openapi-parser

Modern OpenAPI parser written in TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

huypham50 opened this issue · comments

commented

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

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.

commented

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)

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

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

commented

Thanks, I will test once change is live!

Fixed already. ✌️