Getting "require() must have a single string literal argument" when bundling moment.js
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
When attempting to package a project which makes use of the https://github.com/moment/moment.js library, the packager crashes with the error require() must have a single string literal argument
The library line in question is: https://github.com/moment/moment/blob/develop/moment.js#L1830 which appears to be perfectly javascript code.
This behavior does not seem to happen when I build the bundle with RN 0.48.4, however that particular build has issues when running on an phone running Oreo.
I can work around this issue by disabling the error in question by adding a return
statement before this line: https://github.com/facebook/metro-bundler/blob/master/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js#L39
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install
and yarn test
.
I am working on a repo to reproduce this behavior, however my time is limited due to pressing issues that need to be addressed within the next week so I have not been able to get a proper minimalist reproduction of this behavior.
I will update this issue with a link once I can get a good example.
What is the expected behavior?
There should not be any errors when packaging the JS bundle with the above library
Please provide your exact metro-bundler configuration and mention your metro-bundler, node, yarn/npm version and operating system.
RN: 0.49.0-rc.5 metro-bundler: 0.13.0 OS: Arch Linux Mobile OS: Android 8.0.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:60
- Comments:166 (32 by maintainers)
Top GitHub Comments
Since you mentioned me:
I would suggest to notch the entitlement down a little bit. Yes, the situation is frustrating, but as you can see, it was caused by a mutual misunderstanding. The feature never worked in the first place. It is unfortunate that the strict error broke people’s projects, but there is already PR to fix it. Being antagonistic and patronizing in this thread will get you nowhere.
Regardless of the recruiting benefits for Facebook, I want to make it clear that open sourcing something (and then maintaining it at this scale) is always a matter of individual engineers’ commitment to open source. By being antagonistic you are stretching this commitment thin for each of us. Even those who joined from the open source world.
There is no top-down directive at Facebook to build open source software. In fact sometimes we (the engineers) choose to take a hit to our internal productivity and performance because we decide to go the extra mile for what we believe is right. This might be the reason our open source program is so successful: we don’t do vanity projects, and only share the code we heavily use to help move the industry forward. But every thread like this makes me want to do this less and less.
We make mistakes. It is impossible not to at this scale. With hundreds of thousands of dependants, something somewhere is going to break at some point. At the same time we juggle hundreds of other issues internally. It is frustrating if your code doesn’t work after upgrading. However, at the same time, due to today’s bugs, it doesn’t work on master for some teams at Facebook. If we don’t prioritize those problems, nobody at Facebook will want to use React Native, and the project will die. Obviously that would be even worse for the community longer term. So we have to balance the urgency of issues affecting FB and the community, and it is hard. We’re trying our best but I’m curious to know what strategy you would employ if you were in our shoes.
So please, stop with this demanding attitude. We make mistakes, and we are sorry. Sometimes we need help fixing them.
P.S. I’m not working on Metro or React Native. I’m speaking from my own experience, and don’t represent anyone else’s views. But since my employment at FB is being used to justify discussions in this tone, I figured I’d share my view.
Diff landing now, we’ll tag a new release of Metro today. You’ll be able to use Yarn’s selective versions resolution to overwrite the version of Metro used in your RN, see https://code.facebook.com/posts/274518539716230/announcing-yarn-1-0/