我正在使用yarn作为程序包管理器,并且试图像这样使用通用仓库在Web应用程序中为反应本机应用程序创建单仓库。
我正在使用纱线工作区。我进入common
目录,运行yarn link
,然后进入app
目录,并像下面的命令yarn link "@wow/common". Everything seemed to work as "@wow/common" showed up in
mono-repo / packages /那样链接程序包名称。 app / node_modules . I ran
yarn react-native start --reset-cache then
yarn android`,我仍然收到此错误。
yarn run v1.22.4
$ react-native start
###### ######
### #### #### ###
## ### ### ##
## #### ##
## #### ##
## ## ## ##
## ### ### ##
## ######################## ##
###### ### ### ######
### ## ## ## ## ###
### ## ### #### ### ## ###
## #### ######## #### ##
## ### ########## ### ##
## #### ######## #### ##
### ## ### #### ### ## ###
### ## ## ## ## ###
###### ### ### ######
## ######################## ##
## ### ### ##
## ## ## ##
## #### ##
## #### ##
## ### ### ##
### #### #### ###
###### ######
Welcome to React Native!
Learn once, write anywhere
To reload the app press "r"
To open developer menu press "d"
[Tue Apr 07 2020 22:20:19.850] BUNDLE ./index.js
error: Error: Unable to resolve module `@wow/common` from `App.tsx`: @wow/common could not be found within the project.
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules: rm -rf node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
at ModuleResolver.resolveDependency (/home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:186:15)
at ResolutionRequest.resolveDependency (/home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
at DependencyGraph.resolveDependency (/home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/node-haste/DependencyGraph.js:287:16)
at Object.resolve (/home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/lib/transformHelpers.js:267:42)
at dependencies.map.result (/home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:434:31)
at Array.map (<anonymous>)
at resolveDependencies (/home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:431:18)
at /home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
at Generator.next (<anonymous>)
at asyncGeneratorStep (/home/dkendall/Projects/personal/react-projs/mono-repo/packages/app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)
Done in 20.64s.
这是我的 @ wow / common
的 package.json{
"name": "@wow/common",
"description": "Common codebase for web and native apps",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/react-native": "0.62.1",
"bufferutil": "^4.0.1",
"react": "^16.11.0",
"react-native": "^0.62.1",
"utf-8-validate": "^5.0.2"
}
}
我尝试了错误输出中的所有建议步骤
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules: rm -rf node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
我尝试使用import {App} from '../common/dist/index.js'
而不是import {App} from '@wow/common'
如果任何人都可以提供任何解决方案,我将不胜感激。
答案 0 :(得分:2)
我终于解决了这个错误。我的解决方法如下:
#comboBox1-popup.sapMPopover {
max-height: 400px;
}
#comboBox1.sapMPopoverScroll {
max-height: 400px !important;
}
并运行@wow/common
yarn link
并运行@wow/app
yarn link "@wow/common"
中更新(或创建)metro.config.js
:@wow/app
重要的代码段是// /**
// * Metro configuration for React Native
// * https://github.com/facebook/react-native
// *
// * @format
// */
const path = require('path');
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
watchFolders: [
path.resolve(__dirname, '../../../node_modules/@wow/common'),
path.resolve(__dirname, '../../../node_modules'),
],
};
-它告诉应用程序在哪里可以找到通用代码以及其他节点模块(假设您不是 noHoisting依赖项)。
最后,打开两个终端并进入watchFolders
目录并运行:
@wow/app
在1号航站楼yarn start --reset-cache
在2号航站楼我之所以得到这个答案,部分原因是这样的答案:https://stackoverflow.com/a/62033406/11993942