Skip to content

Commit 09ab9b7

Browse files
committed
externals not existing on nitro 3
1 parent 452dfcd commit 09ab9b7

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

packages/nuxt/src/vite/addServerConfig.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,13 @@ export function addServerConfigPlugin(nuxt: Nuxt, serverConfigFile: string, isLe
160160

161161
// The Nitro v2 dev bundle would otherwise externalize these files, making Node load the raw
162162
// `.ts` config — which needs type stripping (Node >= 22.18). Inlining keeps them transpiled.
163-
const externals = (nitroConfig.externals ??= {});
164-
const inline = externals.inline;
165-
const existingInline = Array.isArray(inline) ? inline : inline ? [inline] : [];
166-
externals.inline = [...existingInline, configPath, configPluginTemplate.dst, runtimeFlagsTemplate.dst];
163+
// Nitro v3 has no `externals` option; its dev server runs the config through Vite's transform.
164+
if (isLegacyNitro) {
165+
const externals = (nitroConfig.externals ??= {});
166+
const inline = externals.inline;
167+
const existingInline = Array.isArray(inline) ? inline : inline ? [inline] : [];
168+
externals.inline = [...existingInline, configPath, configPluginTemplate.dst, runtimeFlagsTemplate.dst];
169+
}
167170
});
168171

169172
// On Cloudflare the SDK is set up through `sentryCloudflareNitroPlugin`; the Node SDK config

packages/nuxt/test/vite/addServerConfig.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ describe('addServerConfigPlugin', () => {
208208
expect(nitroConfig.externals?.inline).toEqual(['@sentry/', APP_CONFIG, pluginDst, flagsDst]);
209209
});
210210

211+
it('leaves `externals` alone on Nitro v3, which has no such option', () => {
212+
const { nuxt, hooks } = createFakeNuxt();
213+
addServerConfigPlugin(nuxt, APP_CONFIG, false);
214+
const nitroConfig: NitroConfig = { plugins: ['other-module-plugin.mjs'] };
215+
216+
hooks['nitro:config']!(nitroConfig);
217+
218+
expect(nitroConfig.externals).toBeUndefined();
219+
// Plugin ordering is not Nitro-version specific and still applies.
220+
expect(nitroConfig.plugins).toEqual([pluginDst, 'other-module-plugin.mjs']);
221+
});
222+
211223
it('moves its plugin to the front when other modules registered plugins first', () => {
212224
const { nuxt, hooks } = createFakeNuxt();
213225
addServerConfigPlugin(nuxt, APP_CONFIG, true);

0 commit comments

Comments
 (0)