Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconditional default unwrapping causes problems #22

Open
juanevp opened this issue Feb 6, 2022 · 4 comments
Open

Unconditional default unwrapping causes problems #22

juanevp opened this issue Feb 6, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@juanevp
Copy link

juanevp commented Feb 6, 2022

In line:

code = code.replace(item[0], `${packageName}.default || ${packageName}`);

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.

@dickeylth
Copy link

+1

@jiawulin001 jiawulin001 added the enhancement New feature or request label Feb 16, 2022
@matheusliraofficial
Copy link

matheusliraofficial commented Mar 23, 2022

+1

1 similar comment
@LeeeeeeM
Copy link

+1

@aztack
Copy link

aztack commented Dec 5, 2022

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants