Lerna bootstrap does not link local dependencies
See original GitHub issueI 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:
- 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
- Create the folder structure below
- Copy the files inlined to their corresponding directory
- 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 module-b/node_modules/
still does not contain a reference to module-a
.
Context
I would like to have a build script that executes all tests in all modules as well as having a simple instruction for new project members so that they can be productive in our multi-module project.
I cannot use yarn workspaces 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.
Your Environment
Executable | Version |
---|---|
lerna --version |
3.18.4 |
npm --version |
6.11.3 |
yarn --version |
1.19.1 |
node --version |
v12.12.0 |
OS | Version |
---|---|
NAME | VERSION |
macOS Mojave | 10.14.6 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:76
- Comments:33
Top GitHub Comments
I am also experiencing this issue. Even when using
file: ../module-a
to symlink packages together.I also thought that
lerna bootstrap --force-local
takes care of everything (at least it promises that in the docs), however some local packages are linked, but most are not. I don’t know what the pattern is either.Luckily, this workaround at least added the local links (however, it did not link all hoisted
dependencies
, only some; again, seemingly at random):lerna bootstrap --force-local && lerna link --force-local