2

I've created a react project using yarn and create-react-app with the typescript template and it worked fine even after installing and using other modules. After that I used yarn add react-window and yarn add @types/react-window --dev the following error is raised:

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.

Even after running npm i --save-dev @types/react-window in my dev environment it still results in the same error.

The app runs in docker and fails on the RUN yarn build command. There were no issues prior to using react-window.

What is happening? Other posts on stack overflow regarding this error were solved by installing the types modules (for different libraries), or setting noImplicitAny to false such as here.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Greg
  • 8,175
  • 16
  • 72
  • 125
  • Did `@types/react-window` actually make it into your `package.json`? – spender Aug 31 '21 at 12:44
  • @spender It did but it was under `devDependencies`, the build seems to work now that I manually put it under `dependencies` instead and ran `yarn` again. Should I have used `yarn add @types/react-window` instead of `yarn add @types/react-window --dev` ? – Greg Aug 31 '21 at 12:47
  • It should be a dev-dep, but it shouldn't make too much difference, esp. in a react app where the boundaries are a bit blurry. The packages from both should end up in `node_modules`, and the resolution of those modules at build time depends on them being in `node_modules`. hmm... – spender Aug 31 '21 at 13:00

1 Answers1

1

please use

yarn add @types/react-window --save
chefish
  • 517
  • 2
  • 7
  • 20