-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Upgrade to RN 0.49 - bundling failed: Error: require() must have a single string literal argument #16216
Comments
its fixed in the new version of realm ("realm": "1.13.0"). this is not reactnative issue |
I don't use realm |
which lib has the problem? i had the same issue in Realm and Moment. and both i needed to find a work around for them. you might need to find the require line and fix it. :/ |
the screenshot is all I'm seeing |
@forki Are you using moment js? |
@jeremistadler so what should I do? |
@forki Try |
I added the following to package.json
but now yarn gives me two entries for moment:
that doesn't seem right and also doesn't fix it |
I'm having the same issue with moment. I use react-native-datepicker, which uses moment as its subdependency. Is there a way I can point the react-native-datepicker's moment to the "git+https://github.com/tqc/moment.git#no-dynamic-import"? |
@binchik I think you need to fork |
@albinekb Yeah just did that, thanks. Here is my fork, for anyone having the same issue. https://github.com/binchik/react-native-datepicker |
Same error reproduced. For me, I have the package |
+1 this has broken so many dependencies. I'm hosed until we have a fix. |
@anwarhamr Same. |
+1 |
Metro Bundler breaks again. |
I reverted to 48.4 and working again. I hope this is fixed soon. 💃 |
ok is someone from RN team able to explain the strategy to fix it completely? |
…ted dynamic import
It's so recent, and I think should be fixed asap. By upgrading to |
it's happening when you require an image?! wtf /cc @alfonsogarciacaro looks like you had the right idea. unfortunately |
yeah, basically you'll get the error if doing this against RN
So it's big problem if the image comes from backend response. |
Yep unfortunately moment.js has a require that isn't a string literal, will also be reverting to .48 until this gets sorted 😕 |
With @willymulyana 's example. Is dynamic imports correct Javascript? If so, there's no excuse for "it not being supported" especially when it breaks popular libs like Moment. |
@hramos any official statement from the RN team? |
There's a lot more discussion about this here facebook/metro#65 |
@binchik |
I am facing the same issue while using react-native-gifted-chat. |
nice so no need to put a comment on the require('./locale/' + name); in the \node_modules\moment.js |
To solve the thank @tonybennett |
@gurudev51 It looks like only "moment.js" was fixed in moment 2.19.0. |
upgrading to 0.49 is a pain going to wait till later versions since a handful of dependancies broke. |
any update? moment was upgraded to 2.19 but I'm still facing this error. How can I discover which packages causes this error? Bundling `index.js` [development, non-minified] 99.4% (1401/1405), failed.
error: bundling failed: Error: require() must have a single string literal argument
at pushDependency (/home/prado/projects/fitfood-app/node_modules/metro-bundler/src/JSTransformer/worker/extract-dependencies.js:39:13)
at CallExpression (/home/prado/projects/fitfood-app/node_modules/metro-bundler/src/JSTransformer/worker/extract-dependencies.js:50:9)
at NodePath._call (/home/prado/projects/fitfood-app/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/home/prado/projects/fitfood-app/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/home/prado/projects/fitfood-app/node_modules/babel-traverse/lib/path/context.js:105:12)
at TraversalContext.visitQueue (/home/prado/projects/fitfood-app/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (/home/prado/projects/fitfood-app/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (/home/prado/projects/fitfood-app/node_modules/babel-traverse/lib/context.js:192:19)
at Function.traverse.node (/home/prado/projects/fitfood-app/node_modules/babel-traverse/lib/index.js:114:17) |
Changing seems to work for me. |
Suggest ignoring this version and not upgrading to 4.9.x release There are bugs |
I have this bug in RN 0.50.3 |
I have this bug in RN 0.50.4 trying metro-bundler 0.22.1 resolutions using yarn. but getting this exception
https://github.com/facebook/metro/issues/101
|
Working on RN 0.51.0. Finally! 👍 |
I have same issue with Example: import {Image} from 'react-native';
...
const imageUri = '../../../assets/images/bg.png';
...
<Image source={require(imageUri)} /> And Metro bundler throw this Error: |
I am on RN 0.51 even with moment 2.19.0 and the bug persists. |
I have exact same error as @joaom182. Dynamic import for an |
@grabbou you closed this - but it still persists in RN 0.53 |
@joaom182 @jpmoyn This is not a bug, dynamic image imports via require have never been supported. See https://facebook.github.io/react-native/docs/images.html#images-from-hybrid-app-s-resources |
@kyle-ssg the problem is that require now only accepts string literals - not strings that have been computed. that used to work. |
@forki Sorry but I'm going to have to correct you, I found out this 2-3 years ago attempting to use computed strings. This is due to the way react native packages assets and is not a require related issue. See this 3 year old doc https://github.com/facebook/react-native/blob/0.5-stable/docs/Image.md
|
@kyle-ssg I have code, with UI Tests, that work /shrug |
For requiring images ? Well I'd love to see how you managed that 😄 |
Upgrade to 0.53.0 a couple things changed but, everything is smooth! |
@kyle-ssg I have a theory about why it may have worked for us. What if the image files were already bundled? Then the "static marker" would not be needed, right? Then |
For guys having troubles with images - to do dynamic import you need to require different images in advance and based on some conditions later you put what you want:
then |
Just |
* upgrade native native to avoid issue facebook/react-native#16216
Is this a bug report?
yes
Have you read the Contributing Guidelines?
yes
Environment
react-native.cmd info
Scanning folders for symlinks in D:\code\msu.Reading\node_modules (18ms)
Environment:
OS: Windows 10
Node: 7.0.0
Yarn: 1.0.2
npm: 3.10.9
Watchman: Not Found
Steps to Reproduce
react-native run-android:
Expected Behavior
Normal app start
Actual Behavior
Related
realm/realm-js#1342
realm/realm-js#1346
The text was updated successfully, but these errors were encountered: