Vite build fails with a relative entry path
Steps to reproduce
-
init a new vite react project
-
install vite-plugin-html
-
remove the script tag from
index.htmland add the following tovite.config.js:html({ entry: 'src/main.jsx', // or starting with ./ template: 'index.html', }) -
executing
npm run buildwill result in the following error:Output
➜ npm run build > [email protected] build > vite build vite v2.9.1 building for production... 15:38:34 ✓ 1 modules transformed. 15:38:34 ERROR [vite]: Rollup failed to resolve import "src/main.jsx" 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 error during build: 15:38:34 Error: [vite]: Rollup failed to resolve import "src/main.jsx" 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 (/home/alex/dev/vite-plugin-html-test/node_modules/vite/dist/node/chunks/dep-611778e0.js:39103:19) at onwarn (/home/alex/dev/vite-plugin-html-test/node_modules/vite/dist/node/chunks/dep-611778e0.js:38919:13) at Object.onwarn (/home/alex/dev/vite-plugin-html-test/node_modules/rollup/dist/shared/rollup.js:23129:13) at ModuleLoader.handleResolveId (/home/alex/dev/vite-plugin-html-test/node_modules/rollup/dist/shared/rollup.js:22419:26) at /home/alex/dev/vite-plugin-html-test/node_modules/rollup/dist/shared/rollup.js:22380:26
The build succeeds only with an absolute path in entry (/src/main.jsx), which is confusing - we are usually referencing files relative to the config file we are editing (e.g. template property)
I have the exact same problem and as with your 'workaround' it works when i set /src/main.ts
Thank you for leaving a solution. This worked for me too.
Thanks 🔆
Thank you @cnachtigall1991 Lost 2 hours on this. 🥲
Thank you all guys