当我导入AsyncStorage模块(用于redux-storage)时,我收到以下错误:
ERROR in ./~/react-native/Libraries/react-native/react-native.js
Module parse failed: ~/node_modules/react-native/Libraries/react-native/react-native.js Line 112: Unexpected token ...
You may need an appropriate loader to handle this file type.
| // Note: this must be placed last to prevent eager
| // evaluation of the getter-wrapped submodules above
| ...require('React'),
| };
我的.babelrc扩展了本地反应:
"extends": "react-native/packager/react-packager/.babelrc"
我尝试重新安装本机库但没有帮助。
我正在使用这个github入门套件https://github.com/este/este
检查了webpack配置,如同建议的问题及其相同的https://github.com/facebook/react-native/commit/f9b744d50137de25357994fe2e829f98104e2242
答案 0 :(得分:0)
编辑:已经有一段时间了。今天我强烈反对使用它。只需运行react-native packager。如果你愿意,可以使用.babelrc。没有理由这个模糊的代码,我怀疑它是否仍然有用。
https://gist.github.com/alexesDev/071f8935c82ca87a5b46
这些是拼图的实际部分:
(查看链接了解更多信息)
webpack.config.js;
var reactNativeExternalsPromise = (function () {
var reactNativeRoot = path.dirname(require.resolve('react-native/package'));
var blacklist = require('react-native/packager/blacklist');
var ReactPackager = require('react-native/packager/react-packager');
const rnEntryPoint = require.resolve('react-native');
return ReactPackager.getDependencies({
assetRoots: [__dirname],
blacklistRE: blacklist(false),
projectRoots: [__dirname],
transformModulePath: require.resolve('react-native/packager/transformer'),
}, {
entryFile: rnEntryPoint,
dev: true,
platform: 'ios',
})
.then(function (dependencies) {
return dependencies.filter(function (dependency) {
return !dependency.isPolyfill;
});
})
.then(function (dependencies) {
return dependencies.map(function (dependency) {
return dependency.id;
});
});
}());
和
externals: [
function (context, request, cb) {
reactNativeExternalsPromise.then(function (reactNativeExternals) {
if (['react-native'].concat(reactNativeExternals).indexOf(request) != -1) {
cb(null, request);
} else{
cb();
}
});
}
],