Could not find a declaration file for module '@okta/okta-react'

Walking through the React quickstart application, I get a warning of “Could not find a declaration file for module ‘@okta/okta-react’” when I include the @okta/okta-react package in my App.js file.

The app will start successfully but I will get an error in my Home.js component that says that props.auth is undefined, so it seems that App.js is not able to load the @okta/okta-react package at all.

Searching around a little bit, the consensus seems to be that I need to add a declaration file to the package.json file, so I was wondering if there is one that exists already that I can use. Doing npm install @types/okta__okta-react does not work.

1 Like

Same here. I’m using create-react-app with express and node.js backend. @okta dependencies are in the package.json file. Doing import { withAuth } from “@okta/okta-react” in my component. But getting the “Could not find a declaration file for module ‘@okta/okta-react’” error in code editor and “Unhandled Rejection (TypeError): Cannot read property ‘isAuthenticated’ of undefined” in browser, so auth is undefined because it can’t find the file declaration for okta-react. I also tried specifically installing the types with npm and I tried declaring the module explicitly typescript-style with a okta.d.ts file in src. Nothing worked.