Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hoisting seems broken with npm5 #856

Closed
jquense opened this issue May 30, 2017 · 38 comments
Closed

Hoisting seems broken with npm5 #856

jquense opened this issue May 30, 2017 · 38 comments
Labels
scope: package management Issues with the bootstrap/add/link commands that relate to package management

Comments

@jquense
Copy link

jquense commented May 30, 2017

Expected Behavior

lerna bootstrap --hoist should hoist dependencies when using npm@5

Current Behavior

The correct package.json is generated in the root directory but none of the hoisted deps are installed when a package-lock.json is present....which as far as I can tell (thanks npm docs!) can't be toggled off.

lerna.json

{
  "lerna": "2.0.0-rc.5",
  "version": "4.0.0-rc.6",
  "hoist": true,
  "packages": [
    "packages/*"
  ]
}

Your Environment

Executable Version
lerna --version 2.0.0-rc.5
npm --version 5.0.0
OS Version
macOS ?
@hzoo
Copy link
Contributor

hzoo commented May 30, 2017

Yeah it's definetely not handled yet (nothing on npm 5 is supported since we haven't tested)

@evocateur
Copy link
Member

This is not surprising, but definitely needs to be addressed. Hopefully we can delegate most/all of the bootstrapping logic to npm@5.

@jquense
Copy link
Author

jquense commented May 30, 2017

might be worth making a note of somewhere, node8 is coming out today and ships with (or soon will ship with npm5) Don't want ya'll overrun by folks with the same issue :)

@tivac
Copy link

tivac commented May 30, 2017

#851 is another npm@5 issue similar to this one.

tivac added a commit to tivac/modular-css that referenced this issue Jun 2, 2017
Lerna doesn't really support npm@5 yet, see lerna/lerna#856
@garthk
Copy link
Contributor

garthk commented Jun 5, 2017

Workaround to force npm 4.6 despite a global npm 5, at least when running lerna in the root of your monorepo:

  • npm install --save-dev npm@4.6.1
  • set npmClient to node_modules/.bin/npm in your lerna.json

@rgbkrk
Copy link

rgbkrk commented Jun 6, 2017

Workaround to force npm 4.6 despite a global npm 5

This works well on macOS and Linux, does not work well on Windows as the npm bin references the npm-cli used by *nix systems:


Error: Cannot find module 'C:\projects\nteract\node_modules\.bin\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Function.Module.runMain (module.js:604:10)
    at Function.runMain (C:\Users\appveyor\.node-spawn-wrap-952-2fdd5baf427b\node:40:10)
    at Object.<anonymous> (C:\projects\nteract\node_modules\nyc\bin\wrap.js:23:4)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

We only noticed that via our AppVeyor setup.

@evocateur
Copy link
Member

Notably, if you "manually" hoist all the managed dependencies into the root (thus ensuring lerna bootstrap is mostly a no-op, aside from symlinking), it works with npm@5. Not ideal, but it's a more robust cross-platform workaround.

@MoOx
Copy link

MoOx commented Jun 10, 2017

@evocateur what are you calling "hoisting manually"?

@evocateur
Copy link
Member

evocateur commented Jun 11, 2017 via email

@rgbkrk
Copy link

rgbkrk commented Jun 11, 2017

What would be an ideal way of combining all the dependencies of the subpackages to add to the main package?

@blink1073
Copy link

@rgbkrk, something like this should work (adapted from a JuypterLab script):

var path = require('path');
var glob = require('glob');

/**
 * Handle an individual package on the path - get its dependencies.
 */
function handlePackage(packagePath, data) {
  // Read in the package.json.
  var packagePath = path.join(packagePath, 'package.json');
  try {
    var package = require(packagePath);
  } catch (e) {
    console.log('Skipping package ' + packagePath);
    return;
  }

  var deps = package.dependencies || [];
  for (let dep in deps) {
    data.dependencies[dep] = deps[dep];
  }
}

var data = require('./package.json');

// Handle all of the packages.
var basePath = path.resolve('.');
var files = glob.sync(path.join(basePath, 'packages/*'));
for (var j = 0; j < files.length; j++) {
  handlePackage(files[j], data);
}
console.log(JSON.stringify(data.dependencies, null, 2));

@blink1073
Copy link

Follow up: I just tried the above for JupyterLab here, and not all of the packages are ending up in the top level node_modules after hoisting, meaning we still can't use npm@5.

kring added a commit to magda-io/magda that referenced this issue Jun 25, 2017
* Use node 6 instead of node 8 / npm 5 because of
lerna/lerna#856
* Use urijs instead of the node 7+ URI package.
* Don't ask lerna to hoist all dependencies.  This makes our docker
images smaller because we don't need to put the union of all
dependencies in every image.  tsmonad still needs to be hoisted to work
around microsoft/TypeScript#6496.
* Remove yarn.lock and package-lock.json files.
@Tallyb
Copy link

Tallyb commented Jul 18, 2017

package-lock.json can be disabled using npm config set package-lock false
You probably also want to add in npm config set save false

@blink1073
Copy link

Confirmed that npm config set package-lock false is enough to get us going for now, thanks @Tallyb!

@garthk
Copy link
Contributor

garthk commented Jul 24, 2017

Anyone figured how to set that locally?

@tivac
Copy link

tivac commented Jul 24, 2017

It seems like you could add a .npmrc file to the root of your lerna install, and then set

package-lock = false

in it? Can't test it atm but seems plausible.

@blink1073
Copy link

That should work, package-lock=false is what ends up in my ~/.npmrc with the npm config command.

@tivac
Copy link

tivac commented Jul 24, 2017

It does work, though you need a .npmrc file for the root and every child package. A little annoying, but better than not being able to use bootstrap --hoist.

@redonkulus
Copy link

@jquense @evocateur is there a minimally reproduce-able example we can provide npm so they can debug this issue?

@evocateur
Copy link
Member

I just use relative file: specifiers for sibling dependencies now, don't even use lerna bootstrap anymore. Lerna's own source code demonstrates the usage. npm i packages/* and you're done.

@tivac
Copy link

tivac commented Mar 24, 2018

Or lerna exec -- npm i for cross platform support.

Should we switch to recommending that by default? I'm biased but think so.

@evocateur
Copy link
Member

@tivac Since lerna itself has no problem at all using npm ci with relative file specifiers in its windows builds, I'm inclined to believe that your recent issues migrating modular-css are due to dependencies misbehaving, not cross-platform incompatibility (that would be an issue for npm to fix).

@joebowbeer
Copy link

@tivac Is lerna exec -- npm i really equivalent to npm i packages/*?

@evocateur
Copy link
Member

No, it isn't. Again, it's more than likely a symptom of misbehaving dependencies, not Windows platform-ness. Relative file: specifiers in the root results in basically the same symlink structure as yarn workspaces.

@tivac
Copy link

tivac commented Aug 20, 2018

Yup, sorry everybody, I totally misunderstood the purpose of npm i packages/*. It isn't to run npm i within each of those directories, it's to add them as a file dependency there.

I ran npm i packages\<package> manually for each one of my packages. It added new file dependencies at the root level for each of the child packages. I also previously had manually hoisted all my devDependencies to the root.

But now what? Should npm i from the root install the dependencies of those file: packages?

@evocateur
Copy link
Member

Should npm i from the root install the dependencies of those file: packages?

Yep! The whole tree becomes serialized in the package-lock.json, including relative file: siblings. It's pretty sweet.

@tivac
Copy link

tivac commented Aug 20, 2018

I was running into some trouble with that workflow last night but think I finally got things cleaned up and functioning more cleanly!

Thanks for your patience as I stumbled through this process.

@joebowbeer
Copy link

joebowbeer commented Aug 27, 2018

@evocateur please excuse the follow-ons; I am hoping you can clarify your comment above regarding file: -- I just came across npm/pull/15900 which claims link: is the new file:

BTW it would be great to update the lerna doc to include a description of this golden path free of bootstrap.

@evocateur
Copy link
Member

Yeah, that PR eventually went back to file: without updating the summary. If you run lerna link convert (only needed once), it basically sets you up on the golden path.

I agree I really need to get around to a blog post or something...

@redonkulus
Copy link

@evocateur is lerna link convert an easter egg? Should it be documented on https://github.com/lerna/lerna/tree/master/commands/link#readme?

@evocateur
Copy link
Member

Yeah, sometimes I forget the CLI help isn't automatically shown in the README. And in this case, could definitely use more context. Along with that Lerna 3.0 blog post I've been meaning to write for a few months now...

$ npx lerna link -h
lerna link

Symlink together all packages that are dependencies of each other

Commands:
  lerna link convert  Replace local sibling version ranges with relative file: specifiers

Command Options:
  --force-local  Force local sibling links regardless of version range match                                             [boolean]

(cut off repetitive global options)

@stale
Copy link

stale bot commented Dec 27, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 27, 2018
@stale stale bot removed the stale label Dec 27, 2018
@revelt
Copy link
Contributor

revelt commented May 30, 2019

hi all, I don't see any issues with Lerna hoisting on npm 6.9.0. Please confirm can we close this issue.

t83714 pushed a commit to magda-io/magda-ckan-connector that referenced this issue Feb 2, 2020
* Use node 6 instead of node 8 / npm 5 because of
lerna/lerna#856
* Use urijs instead of the node 7+ URI package.
* Don't ask lerna to hoist all dependencies.  This makes our docker
images smaller because we don't need to put the union of all
dependencies in every image.  tsmonad still needs to be hoisted to work
around microsoft/TypeScript#6496.
* Remove yarn.lock and package-lock.json files.
t83714 pushed a commit to magda-io/magda-csw-connector that referenced this issue Feb 10, 2020
* Use node 6 instead of node 8 / npm 5 because of
lerna/lerna#856
* Use urijs instead of the node 7+ URI package.
* Don't ask lerna to hoist all dependencies.  This makes our docker
images smaller because we don't need to put the union of all
dependencies in every image.  tsmonad still needs to be hoisted to work
around microsoft/TypeScript#6496.
* Remove yarn.lock and package-lock.json files.
t83714 pushed a commit to magda-io/magda-project-open-data-connector that referenced this issue Feb 10, 2020
* Use node 6 instead of node 8 / npm 5 because of
lerna/lerna#856
* Use urijs instead of the node 7+ URI package.
* Don't ask lerna to hoist all dependencies.  This makes our docker
images smaller because we don't need to put the union of all
dependencies in every image.  tsmonad still needs to be hoisted to work
around microsoft/TypeScript#6496.
* Remove yarn.lock and package-lock.json files.
@JamesHenry JamesHenry added the scope: package management Issues with the bootstrap/add/link commands that relate to package management label Jun 14, 2022
@JamesHenry
Copy link
Member

Hi Folks 👋

Please take a look at our published roadmap for Lerna v7 here: #3410

One of the key items covered at length on there (please do read it for full context) is that now that we find ourselves in late 2022, it no longer makes sense for lerna to supplement package management concerns (such as installation, boostrapping, linking etc) which are covered reliably for monorepo workspaces by the three main package managers: npm, yarn and pnpm. lerna bootstrap et al were developed in completely different era of the JavaScript ecosystem.

If you have any specific concerns please do join in on that discussion, and provide as much context as possible.

Many thanks 🙏

@JamesHenry JamesHenry closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2022
@lerna lerna locked and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
scope: package management Issues with the bootstrap/add/link commands that relate to package management
Projects
None yet
Development

No branches or pull requests