Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Types not found with TypeScript 4.7 in ESM mode #1543

Closed
rossng opened this issue May 23, 2022 · 3 comments · Fixed by #1559
Closed

[BUG] Types not found with TypeScript 4.7 in ESM mode #1543

rossng opened this issue May 23, 2022 · 3 comments · Fixed by #1559
Labels
bug Something isn't working

Comments

@rossng
Copy link
Contributor

rossng commented May 23, 2022

1. Read the FAQs 👇

2. Describe the bug

The next version of TypeScript, 4.7, introduces proper support for ESM. It now also supports the package.json exports map. A consequence of this appears to be that the exports map already specified in framer-motion effectively hides the types field and so TypeScript cannot find the types any more.

In the case of the repro below, you will see the following error:

main.ts:1:16 - error TS7016: Could not find a declaration file for module 'framer-motion'. '/home/projects/vitejs-vite-pj1qjj/node_modules/framer-motion/dist/cjs/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/framer-motion` if it exists or add a new declaration (.d.ts) file containing `declare module 'framer-motion';`

1 import {} from 'framer-motion';

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

A CodeSandbox minimal reproduction will allow us to quickly follow the reproduction steps. Without one, this bug report won't be accepted.

https://stackblitz.com/edit/vitejs-vite-pj1qjj?file=main.ts

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Run npm run build

5. Expected behavior

The build should succeed (code itself is trivial/doesn't do anything).

6. Video or screenshots

N/A

7. Environment details

TypeScript 4.7.1-rc

Further details: microsoft/TypeScript#46334

@LuisAlejandro
Copy link

LuisAlejandro commented Jun 29, 2022

This still happens for me with typescript 4.7.4 and framer-motion 6.3.16

Repro: https://stackblitz.com/edit/vitejs-vite-caff2t?file=package.json

@mattgperry mattgperry reopened this Jun 29, 2022
@rossng
Copy link
Contributor Author

rossng commented Aug 8, 2022

I am still encountering issues due to framer-motion pulling in popmotion (and some of its sister packages) which have basically the same problem.

I have opened a PR on that package to address this.

@rossng
Copy link
Contributor Author

rossng commented Aug 10, 2022

After some experimenting, I think the remaining issue is that the existence of the exports map will now cause TypeScript to ignore the top-level types key when in CJS/require mode. The solution for this appears to just be moving the types property up to the top-level of the exports map so that it is always available (rather than only in the import context). I've opened a PR which would do this.

sonnysasaka added a commit to daftarproperti/listings-manager that referenced this issue Oct 16, 2024
popmotion is not a direct dependency, so remove it from package.json's
dependencies. But instead force the version to 11.0.5 via overrides
due to motiondivision/motion#1543.

Change-Id: I515d532fd6f9ff64e83b0c3dcf96c5d24454dc4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants