diff --git a/.storybook/webpack.config.ts b/.storybook/webpack.config.ts
index 75f5734b588..85287fd01ac 100644
--- a/.storybook/webpack.config.ts
+++ b/.storybook/webpack.config.ts
@@ -65,6 +65,17 @@ const prefixReplacer = (prefix, replacements) => {
})
}
+/**
+ * Adds the 'chrome:' scheme to protocol-relative resource URLs.
+ */
+const protocolRelativeReplacer = () => {
+ return new webpack.NormalModuleReplacementPlugin(
+ /^\/\/resources\//,
+ (resource) => {
+ resource.request = `chrome:${resource.request}`
+ })
+}
+
/**
* Attempts to use mock implementations of a provided module name
* the mocked implementation should live in a `__mocks__` folder adjacent to the
@@ -155,11 +166,18 @@ export default async ({ config, mode }) => {
config.plugins.push(
provideNodeGlobals,
useMockedModules(['bridge', 'brave_rewards_api_proxy']),
+ protocolRelativeReplacer(),
...Object.keys(pathMap)
.filter((prefix) => prefix.startsWith('chrome://'))
.map((prefix) => prefixReplacer(prefix, pathMap[prefix]))
)
+ // By default, Webpack will use the "web" externals preset, which will include
+ // an externals plugin that treats module specifiers beginning with `//` as an
+ // external module. Disable the preset so that these modules can be bundled
+ // for storybook.
+ config.externalsPresets = { web: false }
+
// When we aren't running on CI we separate the build and Typecheck phases.
// This results in significantly faster builds (up to 7x faster). On CI we
// join the two stages together so errors break the build.
diff --git a/browser/resources/brave_new_tab_page_refresh/state/search_box_proxy.ts b/browser/resources/brave_new_tab_page_refresh/state/search_box_proxy.ts
index 54f43c8e0c3..cd436aaf232 100644
--- a/browser/resources/brave_new_tab_page_refresh/state/search_box_proxy.ts
+++ b/browser/resources/brave_new_tab_page_refresh/state/search_box_proxy.ts
@@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
-import * as mojom from 'gen/components/omnibox/browser/searchbox.mojom.m'
+import * as mojom from 'chrome://resources/mojo/components/omnibox/browser/searchbox.mojom-webui.js'
import { addCallbackListeners } from '../lib/callback_listeners'
diff --git a/browser/resources/brave_new_tab_page_refresh/state/search_state.ts b/browser/resources/brave_new_tab_page_refresh/state/search_state.ts
index f6790a8ff4a..af37daf6153 100644
--- a/browser/resources/brave_new_tab_page_refresh/state/search_state.ts
+++ b/browser/resources/brave_new_tab_page_refresh/state/search_state.ts
@@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
-import * as mojom from 'gen/components/omnibox/browser/searchbox.mojom.m'
+import * as mojom from 'chrome://resources/mojo/components/omnibox/browser/searchbox.mojom-webui.js'
export const braveSearchHost = 'search.brave.com'
diff --git a/components/brave_new_tab_ui/BUILD.gn b/components/brave_new_tab_ui/BUILD.gn
index c09ee68a433..f3e5a59cf29 100644
--- a/components/brave_new_tab_ui/BUILD.gn
+++ b/components/brave_new_tab_ui/BUILD.gn
@@ -8,7 +8,6 @@ import("//brave/components/common/typescript.gni")
import("//mojo/public/tools/bindings/mojom.gni")
transpile_web_ui("brave_new_tab_ui") {
- output_module = false
entry_points = [ [
"brave_new_tab",
rebase_path("brave_new_tab.tsx"),
diff --git a/components/brave_new_tab_ui/brave_new_tab.html b/components/brave_new_tab_ui/brave_new_tab.html
index 67c4df98b1b..10db31f9a48 100644
--- a/components/brave_new_tab_ui/brave_new_tab.html
+++ b/components/brave_new_tab_ui/brave_new_tab.html
@@ -12,7 +12,7 @@
-
+