rollup/rollup

Input glob error: You must supply options.input to rollup

inwardmovement opened this issue · 2 comments

The input docs says we can generate the inputs with a glob.
I tried in Vite but I get the error You must supply options.input to rollup.

Just run npm create vite@latest, then modify the input object according to the docs.
Repo: https://github.com/inwardmovement/vite-rollup-input-issue

Am I missing something? Is it a problem with Vite?

// vite.config.js

import { defineConfig } from "vite"
import { globSync } from "glob"
import path from "node:path"
import { fileURLToPath } from "node:url"

export default defineConfig({
  build: {
    rollupOptions: {
      input: Object.fromEntries(
        globSync("src/**/*.js").map(file => [
          // This remove `src/` as well as the file extension from each
          // file, so e.g. src/nested/foo.js becomes nested/foo
          path.relative(
            "src",
            file.slice(0, file.length - path.extname(file).length)
          ),
          // This expands the relative paths to absolute paths, so e.g.
          // src/nested/foo becomes /project/src/nested/foo.js
          fileURLToPath(new URL(file, import.meta.url)),
        ])
      ),
    },
  },
})

In your example, the glob is just empty because there is not src folder. If I create the folder and move main.js into the folder, it works as expected. You can just console.log what you pass to input to see that.

@lukastaegert indeed in the example I forgot to add files in src. I had the error in another repo with files in src, but it was because I forgot to add Object.fromEntries... Thanks!