Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite losts <script> in html when I set the root and outDir #16371

Closed
7 tasks done
nyanrus opened this issue Apr 7, 2024 · 4 comments
Closed
7 tasks done

vite losts <script> in html when I set the root and outDir #16371

nyanrus opened this issue Apr 7, 2024 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@nyanrus
Copy link

nyanrus commented Apr 7, 2024

Describe the bug

I am doing to bundle html file with js(ts) files.
What I expect is the js files added to html as script tag as I wrote.
What actually happening is the script tag that importing js files is removed from bundled html.
This is not occuring in pnpm vite dev

the occuring version seems starting from 5.1.0.
this bug don't occur in "5.0.13" and occur in "5.1.0".

Reproduction

https://github.com/nyanrus/vite-minimal

Steps to reproduce

pnpm install
pnpm vite build

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 4.83 GB / 15.93 GB
  Binaries:
    Node: 20.11.0 - ~\AppData\Local\Volta\tools\image\node\20.11.0\node.EXE
    npm: 10.2.4 - ~\AppData\Local\Volta\tools\image\node\20.11.0\npm.CMD
    pnpm: 8.15.1 - C:\Program Files\Volta\pnpm.EXE
    bun: 1.0.27 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (123.0.2420.81)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vite: ^5.2.8 => 5.2.8

Used Package Manager

pnpm

Logs

Click to expand!
  vite:config bundled config file loaded in 50.88ms +0ms
  vite:config using resolved config: {
  vite:config   root: 'C:/Users/user/Desktop/vite-minimal/src',
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     outDir: '../dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: { input: [Object] },
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     ssrEmitAssets: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true },
  vite:config     cssMinify: true
  vite:config   },
  vite:config   configFile: 'C:/Users/user/Desktop/vite-minimal/vite.config.ts',
  vite:config   configFileDependencies: [ 'C:/Users/user/Desktop/vite-minimal/vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     build: {}
  vite:config   },
  vite:config   base: '/',
  vite:config   rawBase: '/',
  vite:config   resolve: {
  vite:config     mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object] ]
  vite:config   },
  vite:config   publicDir: 'C:/Users/user/Desktop/vite-minimal/src/public',
  vite:config   cacheDir: 'C:/Users/user/Desktop/vite-minimal/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   ssr: {
  vite:config     target: 'node',
  vite:config     optimizeDeps: { noDiscovery: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   bundleChain: [],
  vite:config   isProduction: true,
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:force-systemjs-wrap-complete',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   css: { lightningcss: undefined },
  vite:config   esbuild: { jsxDev: false },
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     sourcemapIgnoreList: [Function: isInNodeModules$1],
  vite:config     middlewareMode: false,
  vite:config     fs: {
  vite:config       strict: true,
  vite:config       allow: [Array],
  vite:config       deny: [Array],
  vite:config       cachedChecks: undefined
  vite:config     }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   envDir: 'C:/Users/user/Desktop/vite-minimal/src',
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config       getResolvedCache: [Function: getResolvedCache]
  vite:config     },
  vite:config     set: [Function (anonymous)]
  vite:config   },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: {
  vite:config     holdUntilCrawlEnd: true,
  vite:config     esbuildOptions: { preserveSymlinks: false }
  vite:config   },
  vite:config   worker: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +25ms
vite v5.2.8 building for production...
✓ 3 modules transformed.

(!) outDir C:\Users\user\Desktop\vite-minimal\dist is not inside project root and will not be emptied.
Use --emptyOutDir to override.

../dist/index.html                0.10 kB │ gzip: 0.10 kB
../dist/assets/index-HlKZUkCT.js  0.73 kB │ gzip: 0.41 kB
✓ built in 89ms

Validations

@sapphi-red
Copy link
Member

Duplicate of #15992

@sapphi-red sapphi-red marked this as a duplicate of #15992 Apr 7, 2024
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Apr 7, 2024
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Apr 7, 2024
@nyanrus
Copy link
Author

nyanrus commented Apr 7, 2024

this occurs when using path.resolve in all path too.

@sapphi-red
Copy link
Member

It didn't happen with

import { resolve } from "path";
import { defineConfig } from "vite";

export default defineConfig({
  root: resolve(import.meta.dirname,"src"),
  build: {
    outDir: "../dist",
    rollupOptions: {
      input: {
        index: resolve(import.meta.dirname,"src/index.html"),
      }
    }
  }
})

or

import { resolve } from "path";
import { defineConfig } from "vite";

export default defineConfig({
  root: resolve(import.meta.dirname,"src"),
  build: {
    outDir: "../dist",
    rollupOptions: {
      input: {
        index: resolve("src/index.html"),
      }
    }
  }
})

for me.

Would you describe what config you tried?

@nyanrus
Copy link
Author

nyanrus commented Apr 7, 2024

Thank you for trying.
I recognized I am wrong.
I used resolve even in outDir, and I didn't know that the way resolved the issue.
Thank you!!!!!!!
And sorry for making duplicate.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants