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

Prevent error on safely-handled requires using non-static arguments #69

Conversation

richardgirges
Copy link
Contributor

@richardgirges richardgirges commented Oct 7, 2017

Summary
This is the workaround that @cpojer suggested in #65 and should resolve the biggest pain point that developers are experiencing in that issue: using moment.js in React Native. Hopefully this at least serves as a starting point to reaching a decent solution for libraries using non-static require() statements.

Test plan

1. Two unit tests added:
  • Expected error when non-static-argument-based require() is nested more than one level deep within a try statement
  • Expected no error when non-static-argument-based require() is nested directly within a try statement
2. Ran the following command and got a clean bundle:
ip-192-168-1-10:trueflipapp richard$ react-native bundle --entry-file index.js --platform ios --bundle-output /tmp/test.js --reset-cache
Scanning folders for symlinks in /repo/trueflip/sandbox/code/trueflipapp/node_modules (8ms)
Scanning folders for symlinks in /repo/trueflip/sandbox/code/trueflipapp/node_modules (8ms)
Loading dependency graph, done.
warning: the transform cache was reset.
bundle: start
bundle: finish
bundle: Writing bundle output to: /tmp/test.js
bundle: Done writing bundle output
3. Added the updates to a yarn linked metro-bundle locally and successfully loaded my react native app w/ moment.js as a dependency.

…ectly within a try block. This should prevent the majority of the use cases that cause issue facebook#65. Implementation per @cpojer's suggestions. Two unit tests added.
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@richardgirges
Copy link
Contributor Author

@cpojer I tried to give issue #65 a go in this PR. Please let me know if this looks like a good starting point to getting a fix in.

cc: @TikiTDO who I know has had some pretty significant opinions on this issue. I apologize for doing the same work you were looking into - I couldn't wait much longer due to a large number of dependencies we're using that have moment as a sub-dependency.

@richardgirges
Copy link
Contributor Author

The five errors thrown in the CI were present in the master branch. Didn't want to digress from the issue at hand by fixing them.

@TikiTDO
Copy link

TikiTDO commented Oct 7, 2017

@richardgirges In all honestly, I just want it to work. The sooner the better. If you can get this resolved yesterday my life would be much easier.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 7, 2017
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@richardgirges richardgirges changed the title Prevent error on non-static arguments in safely handled dynamic requires Prevent error on safely-handled requires non-static arguments Oct 7, 2017
@richardgirges richardgirges changed the title Prevent error on safely-handled requires non-static arguments Prevent error on safely-handled requires using non-static arguments Oct 7, 2017
@cpojer
Copy link
Contributor

cpojer commented Oct 7, 2017

Oh nice, thanks for sending this PR. This is definitely the right direction. I'll talk to the Metro team next week about whether this is sufficient or whether we'll need to do other work to make the bundling work properly.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@aethiss
Copy link

aethiss commented Oct 9, 2017

@cpojer we can have some news asap about that issue so ?
Tnx on advance for this job ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants