reactjs - Vercel が Next.js アプリをビルドする際にモジュールや型宣言を見つけられない
Next.jsアプリをVercelにデプロイしようとしていて、react-swipeableには独自の型定義があるようですが、次のことがあります:
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
tsconfig.json に何か追加する必要がありますか?現在は次のようになっています:
{
"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"]
}
いつも通りローカルでは完璧にビルドされます。何か見落としているのでしょうか?
回答 #1
コメントでの@humanbeanの提案に従って、npm i --save-dev @types/react-swipeableを実行したところ、うまくいきました。
ライブラリに組み込み型があるということは他のものは何も必要ないと思っていましたが、間違っていました。