diff --git a/packages/flutter_tools/lib/src/commands/build_web.dart b/packages/flutter_tools/lib/src/commands/build_web.dart
index ca481808089ab6888fb8f72dfffc299478790f8a..06dbab37647e04686c17a57f08a0ab4286791e01 100644
--- a/packages/flutter_tools/lib/src/commands/build_web.dart
+++ b/packages/flutter_tools/lib/src/commands/build_web.dart
@@ -99,6 +99,9 @@ class BuildWebCommand extends BuildSubCommand {
     if (stringArg('base-href') != null && !(stringArg('base-href').startsWith('/') && stringArg('base-href').endsWith('/'))) {
       throwToolExit('base-href should start and end with /');
     }
+    if (!flutterProject.web.existsSync()) {
+      throwToolExit('Missing index.html.');
+    }
     if (!globals.fs.currentDirectory
         .childDirectory('web')
         .childFile('index.html')
diff --git a/packages/flutter_tools/lib/src/web/compile.dart b/packages/flutter_tools/lib/src/web/compile.dart
index ef78ed81b30f57971a834434dd3ddecead928244..18b01d75605187c2831edb216da5be5da24e3cb7 100644
--- a/packages/flutter_tools/lib/src/web/compile.dart
+++ b/packages/flutter_tools/lib/src/web/compile.dart
@@ -28,9 +28,6 @@ Future<void> buildWeb(
   bool nativeNullAssertions,
   String baseHref,
 ) async {
-  if (!flutterProject.web.existsSync()) {
-    throwToolExit('Missing index.html.');
-  }
   final bool hasWebPlugins = (await findPlugins(flutterProject))
     .any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
   final Directory outputDirectory = globals.fs.directory(getWebBuildDirectory());
diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
index fb3db8d2da410ded1b56a75a2ef071a1e74f588a..f4247eb4c7bf054eca5cdc57140772346359165e 100644
--- a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
+++ b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
@@ -14,9 +14,7 @@ import 'package:flutter_tools/src/cache.dart';
 import 'package:flutter_tools/src/commands/build.dart';
 import 'package:flutter_tools/src/commands/build_web.dart';
 import 'package:flutter_tools/src/features.dart';
-import 'package:flutter_tools/src/project.dart';
 import 'package:flutter_tools/src/runner/flutter_command.dart';
-import 'package:flutter_tools/src/web/compile.dart';
 
 import '../../src/common.dart';
 import '../../src/context.dart';
@@ -50,18 +48,12 @@ void main() {
 
   testUsingContext('Refuses to build for web when missing index.html', () async {
     fileSystem.file(fileSystem.path.join('web', 'index.html')).deleteSync();
-    final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
-
-    expect(buildWeb(
-      project,
-      fileSystem.path.join('lib', 'main.dart'),
-      BuildInfo.debug,
-      false,
-      null,
-      true,
-      true,
-      null,
-    ), throwsToolExit());
+    final CommandRunner<void> runner = createTestCommandRunner(BuildCommand());
+
+    expect(
+      () => runner.run(<String>['build', 'web', '--no-pub']),
+      throwsToolExit(message: 'Missing index.html.')
+    );
   }, overrides: <Type, Generator>{
     Platform: () => fakePlatform,
     FileSystem: () => fileSystem,