From 45824edeeeb1fd25ad8102622f0b01a0143d455d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 17 Nov 2024 11:52:05 -0500 Subject: [PATCH] fix(nuxt): handle empty plugin files --- .../nuxt/src/core/plugins/plugin-metadata.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/core/plugins/plugin-metadata.ts b/packages/nuxt/src/core/plugins/plugin-metadata.ts index db6fad7b54..bf2d64c422 100644 --- a/packages/nuxt/src/core/plugins/plugin-metadata.ts +++ b/packages/nuxt/src/core/plugins/plugin-metadata.ts @@ -125,18 +125,26 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { const plugin = nuxt.apps.default?.plugins.find(p => p.src === id) if (!plugin) { return } - const s = new MagicString(code) + if (!code.trim()) { + logger.warn(`Plugin \`${plugin.src}\` has no content.`) + + return { + code: 'export default () => {}', + map: { mappings: '' }, + } + } + const exports = findExports(code) const defaultExport = exports.find(e => e.type === 'default' || e.name === 'default') if (!defaultExport) { logger.warn(`Plugin \`${plugin.src}\` has no default export and will be ignored at build time. Add \`export default defineNuxtPlugin(() => {})\` to your plugin.`) - s.overwrite(0, code.length, 'export default () => {}') return { - code: s.toString(), - map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : null, + code: 'export default () => {}', + map: { mappings: '' }, } } + const s = new MagicString(code) let wrapped = false const wrapperNames = new Set(['defineNuxtPlugin', 'definePayloadPlugin'])