question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Providing build.rollupOptions as an array of RollupOptions objects (i.e. RollupOptions[]) doesn’t work

See original GitHub issue

Describe the bug

According to the documentation for build.rollupOptions it is possible to pass the export of a Rollup config file:

This is the same as options that can be exported from a Rollup config file and will be merged with Vite’s internal Rollup options.

This doesn’t work when the export is a list of rollup options (i.e. RollupOptions[]). From what I can tell, vite just plainly doesn’t ever expect the options provided to be an array; hence, it reports “Unknown input options: 0, 1, 2, 3. Allowed options: acorn, acornInjectPlugins, …” (here, “0, 1, 2, 3” are just the enumerated keys of the object I provided which are just the array indexes of my options). Consequently, the type definitions for vite’s BuildOptions don’t include RollupOptions[] for rollupOptions either. Rollup, however, does allow an array of options (see also: https://github.com/rollup/rollup/blob/e0b10605597ea2f7ee753e6f4e1ae152d19e6508/src/rollup/types.d.ts#L929-L930).

Reproduction

(Note: I’m happy to provide a truly minimal reproduction, but I think this does just fine as the issue doesn’t really seem specific to my project beyond the nature of my build configuration.)

git clone https://github.com/kleinfreund/vue-accessible-color-picker.git
cd vue-accessible-color-picker
git switch migrate-test-suite-to-vitest
npm install

npx vite build

Expected behavior:

The build runs using the provided options just like npx rollup --config does.

Actual behavior:

The build errors (see logs section).

Reproduction

https://github.com/kleinfreund/vue-accessible-color-picker/tree/migrate-test-suite-to-vitest

System Info

System:
    OS: Linux 5.13 Ubuntu 20.04.3 LTS (Focal Fossa)
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 8.5.0 - ~/dev/packages/vue-accessible-color-picker/node_modules/.bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^2.2.0 => 2.2.0 
    vite: ^2.8.3 => 2.8.3

Used Package Manager

npm

Logs

vite:config bundled config file loaded in 135.15ms +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: [ [Object], [Object], [Object], [Object] ],
  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   test: { environment: 'jsdom' },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: { external: [ 'vue', '@vue/server-renderer' ] },
  vite:config   configFile: '/home/phil/dev/packages/vue-accessible-color-picker/vite.config.js',
  vite:config   configFileDependencies: [
  vite:config     'rollup-plugin-discard-css.js',
  vite:config     'rollup.config.js',
  vite:config     'vite.config.js'
  vite:config   ],
  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/phil/dev/packages/vue-accessible-color-picker',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '/home/phil/dev/packages/vue-accessible-color-picker/public',
  vite:config   cacheDir: '/home/phil/dev/packages/vue-accessible-color-picker/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 } +3ms
vite v2.8.3 building for production...
Unknown input options: 0, 1, 2, 3. Allowed options: acorn, acornInjectPlugins, cache, context, experimentalCacheExpiry, external, inlineDynamicImports, input, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileReads, moduleContext, onwarn, perf, plugins, preserveEntrySignatures, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch
✓ 0 modules transformed.
Could not resolve entry module (index.html).
error during build:
Error: Could not resolve entry module (index.html).
    at error (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/rollup/dist/shared/rollup.js:160:30)
    at ModuleLoader.loadEntryModule (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/rollup/dist/shared/rollup.js:22421:20)
    at async Promise.all (index 0)

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Niputicommented, Feb 19, 2022
1reaction
bluwycommented, Feb 19, 2022

Agree with @ydcjeff here. It’s RollupOption without an array according to the types. I’ve checked the code and it would be unintuitive to support an array of options. For now calling Vite with different config files is the way to go.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Certain files not being bundled in ViteJS - Stack Overflow
Consider: - Using dynamic import() to code-split the application - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/ ...
Read more >
Build Options - Vite
Directly customize the underlying Rollup bundle. This is the same as options that can be exported from a Rollup config file and will...
Read more >
rollup.js
To build different bundles with the same input, you supply an array of output options for each input: // rollup. config.
Read more >
vite exports is not defined | The AI Search Engine You Control
_extensions..js (node:internal/modules/cjs/loader:1138:10) at Module.load ... vite:config rollupOptions: { plugins: [Array], output: [Object] }, vite:config ...
Read more >
Build for production - Lit.dev
We recommend Rollup because it's designed to work with the standard ES module format. For a set of sample build configurations using Rollup,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found