Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vite "rollup failed to resolve" build error

Trying to build a simple Vite project that has tailwindcss in it and getting the following error, any ideas?

> [email protected] build
> vite build

vite v2.3.4 building for production...
✓ 1 modules transformed.
[vite]: Rollup failed to resolve import "style.css" from "index.html".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "style.css" from "index.html".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at onRollupWarning (/Users/jmansfield/Sites/vite-project/node_modules/vite/dist/node/chunks/dep-6b5f3ba8.js:45022:19)
    at Object.onwarn (/Users/jmansfield/Sites/vite-project/node_modules/vite/dist/node/chunks/dep-6b5f3ba8.js:44812:13)
    at Object.onwarn (/Users/jmansfield/Sites/vite-project/node_modules/rollup/dist/shared/rollup.js:20122:20)
    at ModuleLoader.handleResolveId (/Users/jmansfield/Sites/vite-project/node_modules/rollup/dist/shared/rollup.js:19143:26)
    at /Users/jmansfield/Sites/vite-project/node_modules/rollup/dist/shared/rollup.js:19097:22
    at async Promise.all (index 0)
    at async ModuleLoader.fetchStaticDependencies (/Users/jmansfield/Sites/vite-project/node_modules/rollup/dist/shared/rollup.js:19095:34)
    at async Promise.all (index 0)
    at async ModuleLoader.fetchModule (/Users/jmansfield/Sites/vite-project/node_modules/rollup/dist/shared/rollup.js:19071:9)
    at async Promise.all (index 0)```
like image 566
James Mansfield Avatar asked May 25 '21 23:05

James Mansfield


2 Answers

It's because build.rollupOptions.external from vite:rollup setup looks for / before external files. So when you add css files to your html just add '/' (eg. /src/foo.css instead of src/foo.css)

like image 165
Palash D Avatar answered Nov 18 '22 13:11

Palash D


Basically vite cannot find the css file you referenced in html. Once I faced with this issue and I changed the way I referenced the css file in html. Either I added or removed ./ from the path.

like image 43
Mostafa Ahangarha Avatar answered Nov 18 '22 14:11

Mostafa Ahangarha