尽管我在react admin中遇到了这个问题,但我认为它与react-admin本身无关:
我的项目中有一些程序包,如下所示:
现在想象ra-data-simple-rest/package.json
如下:
{
"name": "ra-data-simple-rest",
"version": "3.5.5",
"description": "Simple REST data provider for react-admin",
"main": "lib/index.js",
"module": "esm/index.js",
"sideEffects": false,
"files": [
"*.md",
"lib",
"esm",
"src"
],
"authors": [
"François Zaninotto"
],
"repository": "marmelab/react-admin",
"homepage": "https://github.com/marmelab/react-admin#readme",
"bugs": "https://github.com/marmelab/react-admin/issues",
"license": "MIT",
"scripts": {
"build": "yarn run build-cjs && yarn run build-esm",
"build-cjs": "rimraf ./lib && tsc",
"build-esm": "rimraf ./esm && tsc --outDir esm --module es2015",
"watch": "tsc --outDir esm --module es2015 --watch"
},
"dependencies": {
"query-string": "^5.1.1"
},
"devDependencies": {
"cross-env": "^5.2.0",
"rimraf": "^2.6.3"
},
"peerDependencies": {
"ra-core": "^3.0.0"
}
}
因此它具有ra-core
作为其对等依赖项。
现在想象一下我的lerna.json文件如下:
{
"lerna": "2.5.1",
"packages": [
"examples/data-generator",
"packages/*"
],
"version": "3.7.0"
}
当我运行lerna run build
命令时,它首先构建ra-data-simple-rest
,并且由于尚未构建ra-core
,它抱怨ra-core
不能导出某些模块。在我的想象中,lerna应该首先构建ra-core
,然后构建ra-data-simple-rest
,因为ra-data-simpe-rest
具有ra-core
作为对等依赖性,但是为什么不这样做呢?当我将ra-core
放在依赖部分时,问题就解决了。