我有一个react原生应用程序,其中我使用了"json-schema-rules“库。现在我还创建了一个在我的react原生应用程序中使用的库,比如package.json中的"file:../custom_ library“。
现在为了解决版本冲突,我决定在我的自定义库中使用"json-schema-rules“作为对等依赖项。因此,package.json是这样的
我的react原生应用的Package.json:{ "dependencies": { "json-rules-engine": "^2.3.0", "custom_library": "file:../custom_library" } }
my custom_library的package.json:{ "peerDependencies": { "json-schema-rules": "^2.3.0" } }
现在的问题是,每当我使用metro bundler时,我都会得到一个错误: bundling failed: Error: Unable to resolve module json-rules-engine -rules-engine be not be be the project。
这就是我在peerDependencies中使用它时的情况,如果我在依赖中使用这个库,我不会得到任何错误。
请帮帮忙。
发布于 2020-04-29 13:22:45
您可以尝试在项目的babel配置中为模块添加别名。
这意味着当您的自定义包尝试导入"json-rules-engine“时,它将从主应用程序中获得该版本。
首先安装'babel-plugin-module-resolver‘,然后在"module-resolver“中配置别名。
babel.config.js
const config = {
presets: ["module:metro-react-native-babel-preset"],
plugins: [
[
"module-resolver",
{
root: ["./src"],
extensions: [".js", ".jsx", ".ios.js", ".android.js"],
alias: {
"json-rules-engine": require.resolve("json-rules-engine")
}
}
]
]
};
module.exports = config;https://stackoverflow.com/questions/61459162
复制相似问题