oku-ui / motion

Motion One for Vue is a 5kb animation library for Vue 3 and Nuxt 3. Built on Motion One, it's capable of springs, independent transforms, and hardware accelerated animations.
https://motion.oku-ui.com
MIT License
195 stars 4 forks source link

Internal server error: Failed to resolve import "../context" #23

Closed Mehdi-Hp closed 9 months ago

Mehdi-Hp commented 9 months ago

Describe the bug

Vite throws and error that says:

[plugin:vite:import-analysis] Failed to resolve import "../context" from "../node_modules/.pnpm/@oku-ui+motion@0.3.2_vue@3.4.6/node_modules/@oku-ui/motion/dist/component/PresenceGroup.vue". Does the file exist?

It happens for PresenceGroup.vue/Presence.vue/Motion.vue.

If I add extension to the import statement and change import { presenceId } from '../context' to import { presenceId } from '../context.mjs', it workes.


This is probably an issue with unbuild package, but seems to be fixed in version 2.0.0 and I couldn't figure out what version you're using to build the lib.

https://github.com/unjs/mkdist/issues/45 https://github.com/unjs/unbuild/issues/83

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 128.70 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.9.0 - ~/.proto/shims/node
    npm: 10.2.4 - /opt/homebrew/bin/npm
    pnpm: 8.10.2 - ~/.proto/shims/pnpm
  Browsers:
    Chrome: 120.0.6099.216
    Safari: 17.2.1

Used Package Manager

pnpm

Validations

productdevbook commented 9 months ago

can you share a sample repo or stackblitz ?

Mehdi-Hp commented 9 months ago

Turns out it was because of my resolve.extensions config in vite.config.ts.
Before → resolve: { extensions: ['.js', '.ts', '.vue', '.css', '.postcss'] } After → resolve: { extensions: ['.js', '.ts', '.vue', '.css', '.postcss', '.mjs'] }

The default value also works, as it sets to ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']

productdevbook commented 9 months ago

Thank you for writing wonderfully detailed explanations.