motiondivision / motion

A modern animation library for React and JavaScript
https://motion.dev
MIT License
25.66k stars 842 forks source link

[BUG] Failed to resolve entry for package "motion" #2863

Closed aaronbushnell closed 1 week ago

aaronbushnell commented 1 week ago

After installing motion and importing it into a new vanilla JS Vite project I get the following error:

Error:   Failed to scan for dependencies from entries:
  /Users/aaron/Desktop/motion-test/index.html

  ✘ [ERROR] Failed to resolve entry for package "motion". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-scan]

    node_modules/esbuild/lib/main.js:1225:21:
      1225 │         let result = await callback({
           ╵                      ^

    at packageEntryFailure (file:///Users/aaron/Desktop/motion-test/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46637:15)
    at resolvePackageEntry (file:///Users/aaron/Desktop/motion-test/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46634:3)
    at tryNodeResolve (file:///Users/aaron/Desktop/motion-test/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46450:16)
    at ResolveIdContext.resolveId (file:///Users/aaron/Desktop/motion-test/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46200:19)
    at PluginContainer.resolveId (file:///Users/aaron/Desktop/motion-test/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:49015:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async resolve (file:///Users/aaron/Desktop/motion-test/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:49627:22)
    at async file:///Users/aaron/Desktop/motion-test/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:49798:28
    at async requestCallbacks.on-resolve (/Users/aaron/Desktop/motion-test/node_modules/esbuild/lib/main.js:1225:22)
    at async handleRequest (/Users/aaron/Desktop/motion-test/node_modules/esbuild/lib/main.js:647:11)

CodeSandbox reproduction: https://codesandbox.io/p/devbox/mycg74

Steps to reproduce the behavior:

  1. Create a new Vite app using the Vanilla JS template: npm create vite@latest
  2. Install Motion npm i motion
  3. Import motion into main.js: import { animate } from "motion"
  4. Run npm run dev
  5. Error is present

Expected behavior Vite should be able to locate the library

mattgperry commented 1 week ago

I suspect there's a bug here with Codesandbox devbox. If you check node_modules - there is no motion folder. So the error is right because it hasn't been installed. If you then add react or whatever via the packages dialog, both motion and react will be installed and the error disappears.

aaronbushnell commented 1 week ago

Hey @mattgperry, I think it was the updates you made in 11.11.13 that corrected this for me! I had some issues trying to get a Codesandbox setup but I was seeing it consistently fail until updating to 11.11.14 yesterday!