Library works locally, but not when published in Expo 24

I’ve encountered a weird error that I thought I’d reach out to the community for help with. I have an app that uses the library react-native-xml2js ( I’m using it to parse some RSS feeds. This library was working in Expo 22. I updated to Expo 24 and now the app and library work fine locally, but throw an error when published.

To be more specific, I have found that it works fine when serving up the app from my computer (via localhost and via tunneling) to my phone or to my simulator. But the exact same code when published does not work on either my phone or simulator and creates the following error within the react-native-xml2js library:

ReferenceError: Can’t find variable: dc

I went straight from Expo 22 to Expo 24, so I’m not sure if this is also reproducible in Expo 23 or not. For reference, I’m using the latest version of exp (47.4.4).

Initially, I thought it may have been something with the library. But given that it works when running locally, I thought it might instead have to do with the publishing process.

Any idea why I might be seeing this difference in behavior between the published version of the app and the locally served up version of the app? Anyone else seeing similar behavior where something works locally but not when published?


Hi @stevenpal - A couple of months ago the React Native packager updated the version of Uglify (the JS minifier) that it uses for production JS bundles. To help repro this, you could try setting exp/XDE to create the JS bundle with the minify option enabled.

@ide - Yes! That seems to be the cause of the issue. I did exp start --minify and was able to observe the issue locally. And then did exp start --no-minify -c and saw that the issue no longer appeared locally. That definitely points to the minifier being the cause of the problem. Thanks for jumping in and replying so quickly!

Any suggestions on how to resolve the issue?

If you can find where in the bundle this error is happening, it’d be easier to identify what the root cause is. Perhaps there’s a bug with Uglify that is easily fixed or perhaps it’s easier to submit a PR to react-native-xml2js to work around the issue.

Since the error is a ReferenceError rather than a SyntaxError, perhaps you have a stack trace that provides more info?

Great suggestions! The good news is that now that I can reproduce this locally it should be much easier to debug. I was struggling to debug this when the app was published cause I didn’t really have access to any logs (or couldn’t figure out how to access them) so had to do some work arounds to print the errors to screen. Thankfully it doesn’t sound like it’s an issue with Expo. Anyhow, I’ll investigate some more and will let you know if I’m able to resolve it. Thanks again for the help and pointing me in the right direction!

1 Like

Just a quick update here to close the loop. I ended up narrowing down the cause of the issue and have a local patch/workaround for it that I thought I’d share (just in case anyone else has this problem or is more familiar with the minifier and can suggest a proper remedy).

The minifier apparently doesn’t like a section of code in the sax.js library ( that xml2js was dependent on. Although all the javascript looks valid, the minifier must have been doing something wrong right around this line:

I inserted an innocuous line of code after that line and that section of code seems to work fine now when it’s minified by Uglify. If I have more time, I may try to narrow down what the issue is in Uglify. But in the meantime, I have things working locally at least.

@ide Thanks again for your help with this! And just as an aside, it’s been great working with Expo thus far! Awesome platform you guys are building!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.