Getting error after upgrading to 1.0.4
doomsower opened this issue · 5 comments
Code sample:
import { register } from 'react-native-bundle-splitter';
const LazyRegionTabs = register({
require: () => require('./LazyRegionTabs'),
});
After upgrade to 1.0.4 I'm getting this error when rendering LazyRegionTabs
:
TypeError: require is not a function
This error is located at:
in OptimizedComponent
@doomsower Thank you for the reported issue. Could you provide a little bit more details about this error?
Would be nice to know how component LazyRegionTabs
looks or at least which statement are used for exporting component from this file.
BTW This library used on several projects, and migration from 1.0.3
to 1.0.4
didn't affect on these projects - they work as well as previously. And I don't see any breaking changes in the codebase of this library which may lead to the issue that you described
So would be really awesome if you could provide a little bit more context.
Also you can look at test project. There everything works fine with 1.0.4
version.
I don't think the problem is with any particular code, more likely it's with bundling and execution of my app.
I compared dist of react-native-bundle-splitter
versions 1.0.3 and 1.0.4.
There're very few differences. So this is how 1.0.4 is compiled now:
var bundler_1 = require("./bundler");
var cache = {};
exports.isCached = function (componentName) { return !!cache[componentName]; };
exports.getComponent = function (name) {
if (!exports.isCached(name)) {
var _a = bundler_1.mapLoadable[name], require = _a.require, rest = __rest(_a, ["require"]);
// @ts-ignore
var component = require()[rest.extract];
cache[name] = __assign(__assign({}, rest), { component: component });
return cache[name];
}
return cache[name];
};
If I rename scoped require
variable like it's compiled in 1.0.3, it works:
var bundler_1 = require("./bundler");
var cache = {};
exports.isCached = function (componentName) { return !!cache[componentName]; };
exports.getComponent = function (name) {
if (!exports.isCached(name)) {
var _a = bundler_1.mapLoadable[name], require1 = _a.require, rest = __rest(_a, ["require"]);
// @ts-ignore
var component = require1()[rest.extract];
cache[name] = __assign(__assign({}, rest), { component: component });
return cache[name];
}
return cache[name];
};
@doomsower Thank you for the help!
I will fix it and publish new version as soon as possible
@doomsower Can you install 1.0.5
and see if this error exists?
I fixed it, but I would be very happy to hear that someone else can confirm this
Yes, it works now. Thank you!