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

[Packager] this["require"]() form is not supported. Needed for scala-js #465

Closed
gzm0 opened this issue Mar 30, 2015 · 16 comments
Closed

[Packager] this["require"]() form is not supported. Needed for scala-js #465

gzm0 opened this issue Mar 30, 2015 · 16 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@gzm0
Copy link

gzm0 commented Mar 30, 2015

Consider the following two pieces of codeé

this.React = this["require"]("react-native");
this.React = this.require("react-native");

After bundling, we have the following diff:

< __d('AwesomeProject/index.ios',[],function(global, require, requireDynamic, requireLazy, module, exports) {  /**

---
> __d('AwesomeProject/index.ios',["react-native/Libraries/react-native/react-native"],function(global, require, requireDynamic, requireLazy, module, exports) {  /**
943c943
< var React = this["require"]('react-native');

---
> var React = this.require('react-native/Libraries/react-native/react-native');

In the bracket select case, the JSX processor seems to be unable to detect the inclusion, even though the two pieces of code are equivalent from a JavaScript point of view.

See the original post on SO by @ChrisJamesC.

gzm0 added a commit to gzm0/scala-on-ios that referenced this issue Mar 30, 2015
The react-native JSX processor seems to not properly handle imports
when bracket selects are used (see facebook/react-native#465). As a
quick workaround, we pass the output of fullOptJS to react-native.
@vjeux
Copy link
Contributor

vjeux commented Mar 30, 2015

Note that browserify has the same shortcoming. The dependency analyzer just scans for require(string litteral)

@gzm0
Copy link
Author

gzm0 commented Mar 30, 2015

So are you saying that this is actually a browserify issue (as in you are using browserify internally), or just that you are emulating the same behavior?

How desirable and how hard would allowing both syntaxes be to you guys? The issue we are facing is with code that is supports the Google Closure Compiler's advanced mode (generated by Scala.js) and must bracket select in this position if we don't want the call to be renamed. On the other hand, fully minimizing the file is not an option in the development cycle in the long run as it takes too long.

@ide
Copy link
Contributor

ide commented Mar 30, 2015

could you tell Closure that "require" is an extern? https://developers.google.com/closure/compiler/docs/api-tutorial3#externs

@gzm0
Copy link
Author

gzm0 commented Mar 30, 2015

Yes, we could. However, the Scala.js compiler is (currently) not able to emit dot selects for anything but its internal code. Have a look at scala-js/scala-js#761 for a discussion on why supporting both is hard.

@amasad
Copy link
Contributor

amasad commented Mar 30, 2015

I think we can handle this case in the RegExp. If you want to take a shot at it look at
https://github.com/facebook/react-native/blob/master/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js#L603
https://github.com/facebook/react-native/blob/master/packager/react-packager/src/DependencyResolver/haste/index.js#L28

Note there is another PR trying to make it so we share the same Regexp and fixes some issues with whitespace: #316

@brentvatne brentvatne changed the title JSX processor does not handle imports properly with bracket select [Packager] JSX processor does not handle imports properly with bracket select May 31, 2015
@chandu0101
Copy link
Contributor

any progress on this ...

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@gzm0
Copy link
Author

gzm0 commented Aug 6, 2015

What can we do to prevent closure of the issue? This is an issue for (potentially) many JS processors, just closing it because it has been inactive seems odd...

@vjeux
Copy link
Contributor

vjeux commented Aug 6, 2015

@gzmo: that's a very good point, we're working on the bot right now and we still haven't figured out all the use cases. We definitely don't want to close this issue

@amasad
Copy link
Contributor

amasad commented Sep 8, 2015

I want to experiment with moving to an AST-based require analysis, provided it doesn't regress perf that much. Especially know that @martinbigio added caching for module dependencies.

@chandu0101
Copy link
Contributor

@amasad thanks for taking time to look into this, any luck ? , debugging production mode code in development phase is not fun :(

@mariussoutier
Copy link

Bump...

@vjeux
Copy link
Contributor

vjeux commented Dec 16, 2015

@mariussoutier, @gzm0, @chandu0101 any one of you want to take a stab at implementing it on React Native? It is not very hard.

You need to update this regex in order to support both require(...) and ["require"](...): https://github.com/facebook/react-native/blob/master/packager/react-packager/src/DependencyResolver/lib/replacePatterns.js#L14

@vjeux vjeux changed the title [Packager] JSX processor does not handle imports properly with bracket select [Packager] this["require"]() form is not supported. Needed for scala-js Dec 16, 2015
@mariussoutier
Copy link

Done, see #4830.

@chandu0101
Copy link
Contributor

@vjeux thanks alot for pointer

@mariussoutier excellent 👍

@jsierles
Copy link
Contributor

Per the discussion in #2217, this issue seems to have a solution outside of React Native. Internal solutions were downvoted in #4830 as well. So, closing this out. Feel free to discuss mre on the closed issue!

@facebook facebook locked as resolved and limited conversation to collaborators Jul 23, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants