我是Node和Lerna的新手。我来自Java背景,我正尝试使用Lerna创建monorepo节点项目-就像maven及其模块一样。
我当前的项目结构如下:注意package-1
内的package-2/node_modules/
是使用lerna add @me/package-1 --scope=@me/package-2
创建的符号链接
|packages
|package-1
| |node_modules
| | |.bin
| | >cucumber-js
| >package.json
|package-2
| |node_modules
| | |@me
| | |package-1
| | |node_modules
| | | |.bin
| | | >cucumber-js
| >package.json
>lerna.json
>package.json
>package-lock.json
我可以使用2种方式从package-1
中运行Cucumber-js:
package-1/package.json
下添加一个脚本,调用cucumber-js
并在package-1
目录下运行该脚本。例如
...
"scripts": {
"test": "cucumber-js"
}...
~documents/my-project/packages/package-1
$ npm run test
cucumber-js
。例如
~documents/my-project/packages/package-1
$ ./node_modules/.bin/cucumber-js
我相信应该可以从package-2中进行相同的操作,但是到目前为止,我无法使其正常工作。
到目前为止,我尝试像这样从package-2
目录直接进行呼叫:
~documents/my-project/packages/package-2
$ ./node_modules/@me/package-1/node_modules/.bin/cucumber-js
但是我遇到了错误:
Error: Cannot find module 'cucumber' from 'documents\my-project\packages\package-2'
at documents\my-project\packages\package-1\node_modules\resolve\lib\async.js:51:31
at processDirs (documents\my-project\packages\package-1\node_modules\resolve\lib\async.js:185:39)
at ondir (documents\my-project\packages\package-1\node_modules\resolve\lib\async.js:200:13)
at load (documents\my-project\packages\package-1\node_modules\resolve\lib\async.js:83:43)
at onex (documents\my-project\packages\package-1\node_modules\resolve\lib\async.js:108:17)
at documents\my-project\packages\package-1\node_modules\resolve\lib\async.js:12:69
at FSReqWrap.oncomplete (fs.js:152:21)
这是我想做的可能还是意味着我需要为每个相关的软件包安装黄瓜?