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

Type declaration file not found in Next.js app with Typescript #11

Closed
alicia-lyu opened this issue Aug 7, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@alicia-lyu
Copy link

The following static checking error pops up with import { Rating } from "@smastrom/react-rating".

Could not find a declaration file for module '@smastrom/react-rating'. '/path/to/node_modules/@smastrom/react-rating/dist/index.mjs' implicitly has an 'any' type.
There are types at '/path/to/node_modules/@smastrom/react-rating/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@smastrom/react-rating' library may need to update its package.json or typings.ts(7016)

Environment

  • "next": "13.4.12",
  • "react": "18.2.0",
  • "@types/node": "20.4.5",
  • "@types/react": "18.2.17",
  • "@types/react-dom": "18.2.7",
  • "typescript": "5.1.6"

tsconfig.json:

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

My temporary solution

I added a new file react-rating.d.ts in the root directory with the following code:

declare module '@smastrom/react-rating';

The error is resolved.

@alicia-lyu
Copy link
Author

There was a mistake with my tsconfig.json. typeRoots should be ["./node_modules/@types", "./node_modules/*"]. However, this doesn't fix the static checking problem.

I should also mention that even with the temporary fix, there is not auto completion with Rating in my IDE.

@alicia-lyu alicia-lyu reopened this Aug 8, 2023
@smastrom
Copy link
Owner

Hi @alicia-lyu, sorry for getting back to you so late. Yes, there was indeed an issue with react-rating package.json exports field which affected NextJS 13.

I just released a new version that fixes it and adds support for the app router.

Thank you for reporting the issue.

@alicia-lyu
Copy link
Author

Hi @alicia-lyu, sorry for getting back to you so late. Yes, there was indeed an issue with react-rating package.json exports field which affected NextJS 13.

I just released a new version that fixes it and adds support for the app router.

Thank you for reporting the issue.

Don't worry! Thank you for the new release!

@smastrom smastrom added the bug Something isn't working label Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants