React-admin: Could聽not聽find聽a聽declaration聽file聽for聽module聽'react-admin'.

Created on 17 May 2019  路  4Comments  路  Source: marmelab/react-admin

What you were expecting:

No TS error

What happened instead:

TS error

Steps to reproduce:

  1. yarn create react-app my-app --typescript
  2. yarn add react-admin
  3. Open App.tsx and import react-admin
  4. _Could聽not聽find聽a聽declaration聽file聽for聽module聽'react-admin'._

Related code:

import { Create } from 'react-admin';

Other information:

Screenshot 2019-05-17 14 47 38

Environment

  • React-admin version: 2.9.1
  • Last version that did not exhibit the issue (if applicable): N/A
  • React version: 16.8.6
  • Browser: Chrome
  • Stack trace (in case of a JS error): N/A

Most helpful comment

For now my solution is:
react-app-env.d.ts:

// / <reference types="react-scripts" />
declare module 'react-admin';

But with this configuration PhpStorm not provides autocompletion for imports from react-admin.

All 4 comments

Migration to TypeScript is ongoing but not ready yet (see https://marmelab.com/blog/2018/10/18/react-admin-2-4.html). It will take months. Watch the Releases page to be informed when it's ready. In the meantime, disable type checking for that lib.

Part of my tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true
  }
}

I've no compiler errors when importing my js code inside ts module.
I guess the problem is not that react-admin is not fully migrated to TS, but that TS is trying to import from node_modules/react-admin/lib instead of node_modules/react-admin/src

@komik966 I have that set to true already. And yes, that's exactly the issue...

@fzaninotto Hey, me again. Maybe it's an idea to give that a go? I know, I know we had this discussion a couple of years ago when you closed another issue of mine. But I do think this could help.

For now my solution is:
react-app-env.d.ts:

// / <reference types="react-scripts" />
declare module 'react-admin';

But with this configuration PhpStorm not provides autocompletion for imports from react-admin.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fzaninotto picture fzaninotto  路  3Comments

ilaif picture ilaif  路  3Comments

waynebloss picture waynebloss  路  3Comments

aserrallerios picture aserrallerios  路  3Comments

mbj36 picture mbj36  路  3Comments