【发布时间】:2021-01-21 17:44:08
【问题描述】:
我正在尝试将 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"]
}
像往常一样在本地完美构建。我错过了什么吗?
【问题讨论】:
-
是否有解决此库类型的开发依赖项?你可以从那开始
-
@humanbean 你是完全正确的。我认为具有内置类型的库意味着它不需要其他任何东西。但确实如此。
npm i --save-dev @types/react-swipeable工作。谢谢! -
react-swipeable对我来说似乎没有自己的类型定义
标签: reactjs typescript deployment next.js vercel