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

Can't install module with Yarn 3.x (berry) #139

Open
FezVrasta opened this issue Oct 20, 2021 · 11 comments
Open

Can't install module with Yarn 3.x (berry) #139

FezVrasta opened this issue Oct 20, 2021 · 11 comments

Comments

@FezVrasta
Copy link

FezVrasta commented Oct 20, 2021

We have #44 but it's about Yarn 1 I think.

yarn add node results in an error with the following logs:

# This file contains the result of Yarn building a package (node@npm:14.18.1)
# Script name: preinstall

internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module '/Users/federicozivolo/Projects/app/node_modules/node/bin/node'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

I think the problem is that Yarn 3.x runs preinstall hooks as part of the postinstall cycle.

https://yarnpkg.com/advanced/lifecycle-scripts#:~:text=For%20backwards%20compatibility%2C-,preinstall,-and%20install%20are

I'm on macOS 11.6 running Node.js 14.18.1

@aredridel
Copy link
Owner

aredridel commented Oct 20, 2021

Yeah, this sounds like a bug in yarn. They've changed the order of scripts to not be compatible with existing packages.

I urge you to open a bug report there.

@FezVrasta
Copy link
Author

I think they are pushing toward more deterministic packages that don't rely on so many scripts during installation.

Do you think the node npm package could come with everything pre-built to simplify the process?

@aredridel
Copy link
Owner

Not likely. Not unless all architectures (and OSes supported) of node packages were known at the build time of that node release and were included. that'd be > 1GB installed for a node version.

If someone thinks of a clever way to do it I'm all ears.

@FezVrasta
Copy link
Author

Could the package depend on an optionalDependency that would be compatible only for the specific architecture? So the node package would list several optional deps, one for each architecture, and npm/yarn would only download the compatible one.

@aredridel
Copy link
Owner

That doesn't work very well with package-lock.json, because then you end up with the specific architecture locked.

@FezVrasta
Copy link
Author

FezVrasta commented Oct 26, 2021

That doesn't work very well with package-lock.json, because then you end up with the specific architecture locked.

Would this recent addition help?

https://dev.to/arcanis/yarn-31-corepack-esm-pnpm-optional-packages--3hak (conditional packages)

Of course it would mean a Yarn-specific version would be needed. But TBH the Yarn approach seems more reliable

@aredridel
Copy link
Owner

@FezVrasta It might! How does one use such a thing? What file does that stuff that they're describing go into?

@zauni
Copy link

zauni commented Feb 11, 2022

Probably it would help to switch to the approach which esbuild uses and instead of using a post-install script, using the optionalDependencies: evanw/esbuild#1621

Maybe this could prevent a lot of edge cases?

But then the different node packages (operating-systems, CPU combinations) must be available on npm as seperate packages...

@manoraj
Copy link

manoraj commented Jul 12, 2024

I also have this issue in the yarn repository I am working on. For my use case, I had to use https://dotslash-cli.com/ instead of this package.

Considering yarn is the popular package manager, not a bad idea to support this to increase adoption.

@aredridel
Copy link
Owner

Yeah, the reason I haven't done what esbuild does is that adding more architectures or OSes later is impossible, since they have to be listed.

@aredridel
Copy link
Owner

Considering yarn is the popular package manager, not a bad idea to support this to increase adoption.

Increasing adoption for increasing adoption's sake is a non-goal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants