我已经使用yarn
和create-react-app
使用 typescript 模板创建了一个反应项目,即使在安装和使用其他模块之后它也能正常工作。之后我使用yarn add react-window
并yarn add @types/react-window --dev
引发以下错误:
yarn run v1.22.5
$ react-scripts build
Creating an optimized production build...
Failed to compile.
/app/src/components/Table.tsx
TypeScript error in /app/src/components/Table.tsx(1,31):
Could not find a declaration file for module 'react-window'. '/app/node_modules/react-window/dist/index.cjs.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/react-window` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-window';` TS7016
> 1 | import { FixedSizeList } from "react-window";
| ^
2 | import AutoSizer from "react-virtualized-auto-sizer";
3 | import InfiniteLoader from "react-window-infinite-loader";
4 | import { LISTINGS_ENDPOINT } from "../../endpoints";
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
即使npm i --save-dev @types/react-window
在我的开发环境中运行后,它仍然会导致相同的错误。
该应用程序在 docker 中运行并在RUN yarn build
命令上失败。使用前没有任何问题react-window
。
怎么了?有关此错误的堆栈溢出的其他帖子已通过安装类型模块(针对不同的库)或设置noImplicitAny
为false
诸如此处解决。