unjs/unimport

esm import results in faulty cjs require

woldtwerk opened this issue · 3 comments

Environment

18.15.0

Reproduction

import Unimport from 'unimport/unplugin'

export default (options: UserOptions = {}): Plugin[] => {
return [
   ...
    UnimportPlugin.vite(),
    ...
  ].flat()
}

Describe the bug

gets compiled to:

const index = (options = {}) => {
const Unimport = require('unimport/unplugin');
const UnimportPlugin = "default" in Unimport ? Unimport.default : Unimport;
  return [
    ...
    Unimport.vite(),
    ...
  ].flat();
};

module.exports = index;

It should be Unimport.default.vite though

is this an issue with unimport or unbuild?

I'm using "unbuild": "^1.1.2"

Additional context

The use case is that I have a meta plugin that preconfigures a bunch of plugins.

I have a workaround, but would like to know why this happens.
Thank you =)

Logs

No response

antfu commented

We temporarily close this due to the lack of enough information.
Please provide a minimal reproduction to reopen the issue.
Thanks.

Why reproduction is required

sry, I will try to add a minimal reproduction asap