JavaScript
Rollup
Entry Point
Module Bundler
Error Resolution

Could not auto-determine entry point from rollupOptions

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The error Could not auto-determine entry point from rollupOptions occurs in Vite (which uses Rollup internally) when the build configuration does not specify an entry point and Vite cannot find a default index.html file in the project root. This typically happens when building a library without configuring build.lib, when the root directory is misconfigured, or when using Vite for a non-standard project structure. The fix is to explicitly set the entry point in build.rollupOptions.input or configure build.lib for library mode.

The Error

 
1[vite]: Rollup failed to resolve import
2Error: Could not auto-determine entry point from rollupOptions.
3You must either specify input in rollupOptions, or use the "root" option
4to point to a directory with an index.html file.

How Vite Determines the Entry Point

Vite's default behavior for finding the entry point:

  1. Look for index.html in the project root (or the directory specified by root)
  2. Parse index.html for <script type="module" src="..."> tags
  3. Use those script sources as Rollup entry points

If no index.html exists or it does not contain a module script, Vite cannot determine the entry point.

Fix 1: Add index.html (Standard Vite App)

html
1<!-- index.html in project root -->
2<!DOCTYPE html>
3<html lang="en">
4<head>
5    <meta charset="UTF-8">
6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7    <title>My App</title>
8</head>
9<body>
10    <div id="app"></div>
11    <script type="module" src="/src/main.js"></script>
12</body>
13</html>

The <script type="module" src="/src/main.js"> tag tells Vite to use src/main.js as the entry point.

Fix 2: Specify rollupOptions.input (Custom Entry)

javascript
1// vite.config.js
2import { defineConfig } from 'vite'
3import { resolve } from 'path'
4
5export default defineConfig({
6  build: {
7    rollupOptions: {
8      input: resolve(__dirname, 'src/main.js')
9    }
10  }
11})

Multiple Entry Points (Multi-Page App)

javascript
1// vite.config.js
2import { defineConfig } from 'vite'
3import { resolve } from 'path'
4
5export default defineConfig({
6  build: {
7    rollupOptions: {
8      input: {
9        main: resolve(__dirname, 'index.html'),
10        admin: resolve(__dirname, 'admin.html'),
11        login: resolve(__dirname, 'login/index.html')
12      }
13    }
14  }
15})

Fix 3: Configure build.lib (Library Mode)

When building a library (not an application), use library mode instead of relying on index.html:

javascript
1// vite.config.js
2import { defineConfig } from 'vite'
3import { resolve } from 'path'
4
5export default defineConfig({
6  build: {
7    lib: {
8      entry: resolve(__dirname, 'src/index.js'),
9      name: 'MyLibrary',
10      fileName: (format) => `my-library.${format}.js`,
11      formats: ['es', 'umd']
12    },
13    rollupOptions: {
14      // Externalize dependencies that shouldn't be bundled
15      external: ['react', 'react-dom'],
16      output: {
17        globals: {
18          react: 'React',
19          'react-dom': 'ReactDOM'
20        }
21      }
22    }
23  }
24})

Fix 4: Set the root Option

If your index.html is not in the project root:

 
1project/
2├── app/
3│   ├── index.htmlEntry HTML is here
4│   └── src/
5│       └── main.js
6├── vite.config.js
7└── package.json
javascript
1// vite.config.js
2import { defineConfig } from 'vite'
3
4export default defineConfig({
5  root: 'app',  // Vite looks for index.html in ./app/
6  build: {
7    outDir: '../dist'  // Output relative to root
8  }
9})

Fix 5: Pure Rollup Configuration

If you are using Rollup directly (not through Vite):

javascript
1// rollup.config.js
2export default {
3  input: 'src/index.js',  // Required — Rollup has no auto-detection
4  output: {
5    file: 'dist/bundle.js',
6    format: 'esm'
7  }
8}
javascript
1// Multiple inputs
2export default {
3  input: {
4    main: 'src/main.js',
5    utils: 'src/utils.js'
6  },
7  output: {
8    dir: 'dist',
9    format: 'esm'
10  }
11}

Common Project Structures

Single-Page App (SPA)

 
1project/
2├── index.htmlVite finds this automatically
3├── src/
4│   ├── main.js
5│   └── App.vue
6├── vite.config.js
7└── package.json

No extra configuration needed — Vite finds index.html in the root.

Library

 
1project/
2├── src/
3│   ├── index.jsLibrary entry
4│   └── components/
5├── vite.config.jsMust configure build.lib
6└── package.json

Requires build.lib.entry in vite.config.js.

Monorepo Package

 
1packages/
2├── ui-library/
3│   ├── src/index.ts
4│   ├── vite.config.tsMust configure build.lib or rollupOptions.input
5│   └── package.json
6└── web-app/
7    ├── index.html
8    ├── vite.config.tsWorks automatically
9    └── package.json

Common Pitfalls

  • Missing index.html in root directory: Vite requires index.html in the root (or the root option directory) for application mode. If you moved it to public/ or src/, either move it back or set root accordingly.
  • index.html without <script type="module">: An index.html that only has regular <script> tags (not type="module") does not provide Vite an entry point. Add type="module" to your script tag.
  • Using build.lib and rollupOptions.input simultaneously: When both are specified, they can conflict. In library mode, use build.lib.entry for the entry point. rollupOptions.input is for application mode or overriding specific Rollup behavior.
  • Relative paths in rollupOptions.input: Always use resolve(__dirname, 'path') for entry points. Relative paths resolve from the working directory, which may differ between development and CI environments.
  • Vite config in wrong location: vite.config.js must be in the project root (next to package.json). If it is in a subdirectory, Vite will not find it and uses defaults, which may not locate your index.html.

Summary

  • Vite auto-detects entry points from index.html in the project root — the error means it could not find one
  • For standard apps, ensure index.html exists at the root with a <script type="module"> tag
  • For libraries, configure build.lib.entry in vite.config.js
  • For custom structures, set rollupOptions.input or the root option
  • For multi-page apps, pass an object to rollupOptions.input with named entries
  • Always use resolve(__dirname, 'path') for absolute entry point paths

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.