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.

`build.rollupOptions.dir` and `build.rollupOptions.file` no longer work as expected

See original GitHub issue

Describe the bug

I have been using vite 2.9 before updating to 3.2.4 and building a single bundle.js file with npm run build. After updating – it has become no longer possible to build the app to a single file due to one of the following errors:

Error no. 1:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null

or Error no.2:

Error: Invalid value for option "output.dir" - you must set either "output.file" for a single-file build or "output.dir" when generating multiple chunks

Essentially, specifying dir: null which has worked previously now gives the “Error no. 1” output Meanwhile, specifying ONLY file: ... now gives “Error no. 2” output.

Both errors seem to conflict with one another leading to an endless cycle of resolving one - points to another and vice versa.

Reproduction

https://github.com/kgataveckastg/vite-dir-file-bug

Steps to reproduce

yarn create vite --template=react-ts

vite.config.ts:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      output: {
        file: path.resolve('./dist', 'bundle.js'),
        format: 'iife',
      }
    }
  }
})

Run npm run build

System Info

System:
    OS: macOS 13.0.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 818.66 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.1 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 8.15.0 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 105.1.43.93
    Chrome: 103.0.5060.114
    Safari: 16.1
  npmPackages:
    @vitejs/plugin-react: ^2.2.0 => 2.2.0 
    vite: ^3.2.4 => 3.2.4 


### Used Package Manager

npm

### Logs

_No response_

### 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 [vuejs/core](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.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sapphi-redcommented, Dec 7, 2022

An example is:

export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      output: {
        dir: path.resolve('./dist'),
        entryFileNames: 'bundle.js',
        format: 'iife',
      }
    }
  }
})
0reactions
kgataveckastgcommented, Dec 7, 2022

Thank you, it looks to be working fine now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web Worker imports don't respect rollupOptions.output ...
Go to sample project on Stackblitz; Open terminal; yarn build; Observe /dist/assets folder output. Expected: All files without hash. Actual:.
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 >
Vite "rollup failed to resolve" build error - tailwind css
It's because build.rollupOptions.external from vite:rollup setup looks for / before external files. So when you add css files to your html ...
Read more >
Vite Configuration - AEM Vite
The following is intended to provide coverage for general ... (saves 2-5 seconds per prod build); Disables the manifest.json file ...
Read more >
How to preprocess Cypress tests with Vite - Adam Lynch
Vite is a blazing fast feature-rich build tool from the creator Vue ... rollupOptions.input ) and which directory to write output file(s) to ......
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