Lerna 引导程序不链接本地依赖项? [英] Lerna bootstrap does not link local dependencies?

查看:21
本文介绍了Lerna 引导程序不链接本地依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 lerna 和本地依赖项的正确方法是什么?

<小时>

我在单声道存储库中配置了两个模块以使用具有本地依赖项的 lerna.我预料到了

$ lerna bootstrap$ lerna 运行测试

足以下载所有外部依赖项、链接本地依赖项并执行并通过所有模块中的所有测试.

预期行为

根据 lerna bootstrap 文档:

<块引用>

  1. 将所有相互依赖的 Lerna 包符号链接在一起.

因此,我希望 lerna bootstrap 会在 module-b/node_modules 下面创建一个符号链接,指向 module-a(然后将允许执行并通过测试).

当前行为

未发生链接,导致测试失败:

<块引用>

勒娜错了!纱线运行测试在模块-b"中退出 1勒纳错了!纱线运行测试标准输出:纱线运行 v1.19.1$开玩笑信息访问 https://yarnpkg.com/en/docs/cli/run 获取文档关于这个命令.

勒娜错了!纱线运行测试标准错误:失败 ./import.test.js● 测试套件运行失败

无法从import.test.js"中找到模块module-a">1 |const moduleA = require('module-a');|^2 |3 |test('应该导入模块-a', () => {4 |模块A();在 Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)在对象<匿名>(import.test.js:1:1)

重现步骤

  1. 在下面创建文件夹结构
  2. 将内联的文件复制到其对应目录
  3. 执行$ lerna bootstrap,然后是$ lerna run test

project-root+ 包|+ 模块-a||+ package.json||+ index.js|||+ 模块-b||+ package.json||+ import.test.js|+ lerna.json

packages/module-a/package.json

<代码>{"name": "module-a","版本": "1.0.0",私人":真的,"main": "index.js",脚本":{"test": "echo \"测试通过模块-a\""}}

packages/module-a/index.js

module.exports = () =>console.log('登录模块-a');

packages/module-b/package.json

<代码>{"name": "module-b","版本": "1.0.0",私人":真的,"main": "index.js",脚本":{测试":开玩笑"},依赖关系":{模块-a":文件:../模块-a"},开发依赖":{开玩笑":^24.9.0"}}

packages/module-b/import.test.js

const moduleA = require('module-a');test('应该导入模块-a', () => {模块A();});

lerna.json

<代码>{"npmClient": "纱线",包":[包/*"],版本":独立"}

观察

执行 lerna 链接 --force-local 没有改变现状,测试仍然失败,因为 module-b/node_modules/ 仍然不包含对 module-a 的引用.

备注

我不能将 yarn 工作区 与 lerna 一起使用,因为 module-b 是一个 Electron 应用程序,并且 Electron 构建器希望它的依赖项安装在 packages/module-b/node_modules/ 文件夹中.

环境

  • lerna --version 3.18.4
  • npm --version 6.11.3
  • 纱线 --version 1.19.1
  • node --version v12.12.0
  • macOS Mojave 10.14.6

解决方案

我已经尝试过你的实现.

packages/module-b/package.json 中使用 file:../module-a 对我不起作用.

您可以通过为 module-a 编写一个版本号来轻松绕过它(因为我们将 force-local,所以这并不重要)

<代码>{"name": "module-b","版本": "1.0.0",私人":真的,"main": "index.js",脚本":{测试":开玩笑"},依赖关系":{模块-a":1.0.0"},开发依赖":{开玩笑":^24.9.0"}}

在项目的根目录:

本地版本的引导程序和链接:

npx lerna bootstrap --force-local

运行测试:

npx lerna 运行测试

What is the proper way of working with lerna and local dependencies?


I have configured two modules in a mono repo to use lerna with a local dependency. I expected that

$ lerna bootstrap
$ lerna run test

would be sufficient to download all external dependencies, link a local dependency and execute and pass all tests in all modules.

Expected Behavior

As per the lerna bootstrap documentation:

  1. Symlink together all Lerna packages that are dependencies of each other.

Thus, I expected that lerna bootstrap would create a symlink in module-b/node_modules below that points to module-a (which then would allow the tests to be executed and pass).

Current Behavior

No linking occurs, which cause the tests to fail:

lerna ERR! yarn run test exited 1 in 'module-b' lerna ERR! yarn run test stdout: yarn run v1.19.1 $ jest info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

lerna ERR! yarn run test stderr: FAIL ./import.test.js ● Test suite failed to run

Cannot find module 'module-a' from 'import.test.js'

> 1 | const moduleA = require('module-a');
    | ^
  2 | 
  3 | test('should import module-a', () => {
  4 |   moduleA();

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at Object.<anonymous> (import.test.js:1:1)

Steps to Reproduce

  1. Create the folder structure below
  2. Copy the files inlined to their corresponding directory
  3. Execute $ lerna bootstrap followed by $ lerna run test

project-root
   + packages
   |       + module-a
   |       |      + package.json
   |       |      + index.js
   |       |
   |       + module-b
   |       |      + package.json
   |       |      + import.test.js
   |
   +  lerna.json     

packages/module-a/package.json

{
  "name": "module-a",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "scripts": {
    "test": "echo \"Test passed in module-a\""
  }
}

packages/module-a/index.js

module.exports = () => console.log('Log in module-a');

packages/module-b/package.json

{
  "name": "module-b",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "dependencies": {
    "module-a": "file:../module-a"
  },
  "devDependencies": {
    "jest": "^24.9.0"
  }
}

packages/module-b/import.test.js

const moduleA = require('module-a');

test('should import module-a', () => {
  moduleA();
});

lerna.json

{
  "npmClient": "yarn",
  "packages": [
    "packages/*"
  ],
  "version": "independent"
}

Observation

Executing lerna link --force-local does not change status quo, the test still fails because the module-b/node_modules/ still does not contain a reference to module-a.

Remark

I cannot use yarn workspaces together with lerna because module-b is an Electron app and the electron builder expects its dependencies to be installed in the packages/module-b/node_modules/ folder.

Environment

  • lerna --version 3.18.4
  • npm --version 6.11.3
  • yarn --version 1.19.1
  • node --version v12.12.0
  • macOS Mojave 10.14.6

解决方案

I have tried your implementation.

Using file:../module-a in packages/module-b/package.json does not work for me.

You can go around it easily by using writing a version number for module-a (it does not matter which since we will force-local)

{
  "name": "module-b",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "dependencies": {
    "module-a": "1.0.0"
  },
  "devDependencies": {
    "jest": "^24.9.0"
  }
}

At the root of your project:

Bootstrap and link for local version:

npx lerna bootstrap --force-local

Run tests:

npx lerna run test

这篇关于Lerna 引导程序不链接本地依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆