Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

default export modification for plugins does not work with rollup / siroc builds. #203

Open
ayalon opened this issue Sep 21, 2021 · 1 comment
Labels
bug Something isn't working needs-reproduction

Comments

@ayalon
Copy link

ayalon commented Sep 21, 2021

In Rollup recently an important change was made to solve issues with named export and default exports.
See rollup/rollup#4182

The most important change is that default exports are now always rendered as
export {binding as default};
instead of
export default binding;

If you use siroc (which uses Rollup) to build your nuxt plugin, you will get the following export in your plugin:
export { myplugin as default };

This is fine and correct.

Unfortunatly the defaultExportPlugin() nuxt vite scrables these files:

/src/plugins/default-export.ts

const hasDefaultExport = (code: string = '') => code.includes('export default')
const addDefaultExport = (code: string = '') => code + '\n\n' + 'export default () => {}'

The plugin only searches for export default and will add another export default () => {} at the end resulting in
Duplicate export 'default' error.

The defaultExportPlugin() export plugin should also search for default exports in a different notation like that:

const hasNamedDefaultExport = (code: string = '') => code.includes('as default')

The search string is not very prone to false positives but it shows the issue.

@ayalon ayalon added the bug Something isn't working label Sep 21, 2021
@pi0
Copy link
Member

pi0 commented Sep 21, 2021

Hi @ayalon. Would you please provide a minimal reproduction?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working needs-reproduction
Projects
None yet
Development

No branches or pull requests

3 participants