Unconditional default unwrapping causes problems
In line: https://github.com/originjs/vite-plugins/blob/74b73c3069dafa328a5d57da276d9d77f6b712ff/packages/vite-plugin-commonjs/src/lib.ts#L37
the transformation unconditionally unwraps the default property of exports if present. I use a library which assumes that require() returns an object with a default property and it is failing because the code ends up double-unwrapping which produces an undefined value.
AFAIK, unwrapping the default export is not part of the require expected behavior.
Versions
- originjs: 1.0.2
- node: 16.13.1
Reproduction
This is the case I am referring to specifically. In this line que component is required: https://github.com/martinnov92/React-Splitters/blob/c9ca351426e55c41c2016c9cc1c647dd17974783/lib/Splitter.js#L20
In this line is it used: https://github.com/martinnov92/React-Splitters/blob/c9ca351426e55c41c2016c9cc1c647dd17974783/lib/Splitter.js#L288
See that the use expects to have the default property.
Additional Details
Steps to reproduce
What is Expected?
That the transformed code be:
import * as __require_for_vite_JvR9OZ from "./Pane";
/*...*/
var Pane_1 = __require_for_vite_JvR9OZ;
/*...*/
React.createElement(Pane_1.default, /*...*/),
What is actually happening?
import * as __require_for_vite_JvR9OZ from "./Pane";
/*...*/
var Pane_1 = __require_for_vite_JvR9OZ.default || __require_for_vite_JvR9OZ;
/*...*/
React.createElement(Pane_1.default, /*...*/),
Which produces the error:
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Given the require semantics I think this should be considered a bug,. The default behavior should not automatically unwrap the default property. Maybe this behavior could be specified through a setting.
+1
+1
+1
+1