vite-plugin-html icon indicating copy to clipboard operation
vite-plugin-html copied to clipboard

Vite build fails with a relative entry path

Open alex-kim-dev opened this issue 3 years ago • 5 comments

Steps to reproduce

repo

  1. init a new vite react project

  2. install vite-plugin-html

  3. remove the script tag from index.html and add the following to vite.config.js:

    html({
      entry: 'src/main.jsx', // or starting with ./
      template: 'index.html',
    })
    
  4. executing npm run build will 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)

alex-kim-dev avatar Apr 06 '22 11:04 alex-kim-dev

I have the exact same problem and as with your 'workaround' it works when i set /src/main.ts

VikingOwl91 avatar Apr 13 '22 07:04 VikingOwl91

Thank you for leaving a solution. This worked for me too.

JoshuaHintze avatar Jul 07 '22 02:07 JoshuaHintze

Thanks 🔆

yoochangoh avatar Sep 05 '22 02:09 yoochangoh

Thank you @cnachtigall1991 Lost 2 hours on this. 🥲

sh-ravan avatar May 23 '23 15:05 sh-ravan

Thank you all guys

tjyuanpeng avatar Aug 10 '23 02:08 tjyuanpeng