I've been following this video to build a shareable Vue component via Vite, which I'm then testing by npm linking it into another project.
After building with Vite via npm run bulid and then linking, I end up with this structure in my other project's node_modules dir:
- mycomponent
- dist
- style.css
- mycomponent.es.js
- mycomponent.umd
I can successfully import my component - BUT it lacks CSS! So according to the above video I needed to do (in my main.js):
import MyComponent from 'mycomponent'
import 'mycomponent/dist/style.css'
...
const app = createApp(App)
.use(...)
.use(Mycomponent)
I don't really want it to be globally available in this way, but I'm just trying to fix the CSS issue. Anyway, this results in the following error:
[plugin:vite:import-analysis] Missing "./style.css" export in "mycomponent" package
What am I doing wrong? Given my component was built as a SFC, why do I even need to import its CSS separately? And the file /dist/style.css does exist.
Here's my component's package.json > exports, incidentally:
"exports": {
".": {
"import": "./dist/mycomponent.es.js",
"require": "./dist/mycomponent.umd.js"
},
"./dist/style.css": "./dist/style.css"
},
Thank you in advance!
Failed:
In my case I had...
"./style.css": "./dist/style.css"
and so got the OP error trying to import 'my-lib/dist/style.css'.
Solution:
Match the import to the key from exports, like
import 'my-lib/style.css'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With