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

space in file names causes build failure

Open danielroe opened this issue 3 years ago • 1 comments

Describe the bug

Adding a space in a public asset file name causes a build (but not development) failure.

Originally reported at https://github.com/nuxt/nuxt.js/issues/13494.

Reproduction

https://stackblitz.com/edit/vitejs-vite-o8aged

System Info

System:
    OS: macOS 12.2.1
    CPU: (8) x64 Apple M1
    Memory: 59.79 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.18.3 - ~/.volta/tools/image/node/14.18.3/bin/node
    Yarn: 3.2.0 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
    npm: 8.3.2 - ~/.volta/tools/image/npm/8.3.2/bin/npm
  Browsers:
    Brave Browser: 97.1.34.80
    Edge: 99.0.1150.39
    Firefox Developer Edition: 99.0
    Safari: 15.3

Used Package Manager

yarn

Logs

$ vite build --debug
  vite:config bundled config file loaded in 119.00ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  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',
  vite:config     'vite:worker',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:asset-import-meta-url',
  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   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: 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   },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: { external: [ 'vue', '@vue/server-renderer' ] },
  vite:config   configFile: '/home/projects/vitejs-vite-o8aged/vite.config.js',
  vite:config   configFileDependencies: [ 'vite.config.js' ],
  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   root: '/home/projects/vitejs-vite-o8aged',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '/home/projects/vitejs-vite-o8aged/public',
  vite:config   cacheDir: '/home/projects/vitejs-vite-o8aged/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  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   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     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: {
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   },
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object]
  vite:config     ],
  vite:config     rollupOptions: {}
  vite:config   }
  vite:config } +2ms
vite v2.8.6 building for production...
✓ 5 modules transformed.
[vite]: Rollup failed to resolve import "/public/fav%20icon.ico" from "src/App.vue".
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 "/public/fav%20icon.ico" from "src/App.vue".
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/projects/vitejs-vite-o8aged/node_modules/vite/dist/node/chunks/dep-9c153816.js:39242:19)
    at onwarn (/home/projects/vitejs-vite-o8aged/node_modules/vite/dist/node/chunks/dep-9c153816.js:39020:13)
    at Object.eval [as onwarn] (/home/projects/vitejs-vite-o8aged/node_modules/rollup/dist/shared/rollup.js:23129:13)
    at ModuleLoader.handleResolveId (/home/projects/vitejs-vite-o8aged/node_modules/rollup/dist/shared/rollup.js:22419:26)
    at eval (/home/projects/vitejs-vite-o8aged/node_modules/rollup/dist/shared/rollup.js:22380:26)
[!] Error: unfinished hook action(s) on exit:
(vite:load-fallback) load "/home/projects/vitejs-vite-o8aged/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js"


### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitejs.dev/guide).
- [X] Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

danielroe avatar Mar 12 '22 23:03 danielroe

It seems this is an issue that only happens in Vue, moving the issue to vite-plugin-vue.

But from what I gather, the SFC compiler is encoding the space as part of moving the img src to an import transformAssetUrls

There is an open PR here (this issue is also affecting VitePress)

  • https://github.com/vuejs/core/pull/8752

I don't know if the PR is correct though, or if vite-plugin-vue would deal with this. I would expect this needs to be fixed in Vue.

patak-dev avatar Aug 01 '23 14:08 patak-dev

Closing as it can't reproduce with:

  "dependencies": {
    "vue": "3.5.8"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "5.1.4",
    "vite": "5.4.7"
  }

edison1105 avatar Sep 25 '24 07:09 edison1105