Tìm kiếm trang web

reactjs - Vercel không thể tìm thấy module hoặc khai báo kiểu khi xây dựng ứng dụng Next.js


Tôi đang cố gắng triển khai một ứng dụng Next.js lên Vercel và react-swipeable dường như có các khai báo kiểu riêng nhưng:

Running "npm run build"
...
> next build
...
Failed to compile.
./components/SwipeBox.tsx:5:30
Type error: Cannot find module 'react-swipeable' or its corresponding type declarations.
  3 | 
  4 | import { NextPage } from "next";
> 5 | import { useSwipeable } from "react-swipeable";
    |                              ^
  6 | 
  7 | interface SwipeBoxProps {
  8 |   children: React.ReactNode;
...
Error: Command "npm run build" exited with 1

Tôi có cần thêm gì vào tsconfig.json không? Hiện tại nó trông như sau:

{
  "compilerOptions": {
    "target": "es2020",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "checkJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "next.config.js"],
  "exclude": ["node_modules", "next.config.js"]
}

Xây dựng hoàn hảo trên máy cục bộ như thường lệ. Tôi có đang thiếu điều gì không?

Câu trả lời #1

Theo đề xuất của @humanbean trong bình luận, tôi đã chạy npm i --save-dev @types/react-swipeable và nó đã hoạt động.

Tôi nghĩ rằng thư viện có các kiểu tích hợp nghĩa là nó không cần gì khác, nhưng tôi đã sai.