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

Corepack not available #26

Closed
hterik opened this issue Dec 1, 2021 · 5 comments
Closed

Corepack not available #26

hterik opened this issue Dec 1, 2021 · 5 comments

Comments

@hterik
Copy link

hterik commented Dec 1, 2021

Corepack is supposed to be included in Node > 16.10, but needs to be activated using corepack enable. When installing node with snap it seems like something is missing for this to work.
Steps to reproduce:

$ sudo snap install node --classic --channel=16
node (16/stable) 16.13.0 from OpenJS Foundation (iojs✓) installed
$ node --version
v16.13.0
$ corepack enable
corepack: command not found

I can still see the corepack binary is there under /snap/node/current/bin/corepack. But running it gives some other error:

$ /snap/node/current/bin/corepack enable
Internal Error: not found: corepack
    at getNotFoundError (/snap/node/5534/lib/node_modules/corepack/dist/corepack.js:13867:17)
    at /snap/node/5534/lib/node_modules/corepack/dist/corepack.js:13914:18
    at new Promise (<anonymous>)
    at step (/snap/node/5534/lib/node_modules/corepack/dist/corepack.js:13911:21)
    at /snap/node/5534/lib/node_modules/corepack/dist/corepack.js:13928:22
    at new Promise (<anonymous>)
    at subStep (/snap/node/5534/lib/node_modules/corepack/dist/corepack.js:13926:33)
    at /snap/node/5534/lib/node_modules/corepack/dist/corepack.js:13937:22
    at /snap/node/5534/lib/node_modules/corepack/dist/corepack.js:5369:5
    at /snap/node/5534/lib/node_modules/corepack/dist/corepack.js:5402:5

@rvagg
Copy link
Member

rvagg commented Dec 1, 2021

OK, so this is probably going to be complicated.

PATH=$PATH:/snap/node/current/bin corepack enable will work because your error there is that it can't find corepack in the PATH, but you'll get another error because it's going to want to set up binaries in the Snap's bin directory, which it's not allowed to touch. You could PATH=$PATH:/snap/node/current/bin corepack enable --install-directory=/usr/local/bin to install it there.

I'm not sure the corepack model is going to be suitable for the Snap because of this need to install in a different path. It's just going to confuse users I suspect.

yarn and yarnpkg are already installed with the Snap, along with npm and npx. So only pnpm and pnpx are missing I think from what corepack offers? I think if these are genuinely worthwhile to you and maybe other users then you could help just get it installed straight into the Snap itself, making corepack unnecessary.

Unfortunately it's not a straightforward task. Have a look at https://github.com/nodejs/snap/blob/HEAD/snapcraft.yaml.sh, which generates https://github.com/nodejs/snap/blob/HEAD/snapcraft.yaml for each release line. If you get yourself setup to develop Snaps locally you can build them straight from these configs and try them out on your local machine. Have a look in the file for yarn and you'll see there's a couple of things that need doing: (1) download and install the package into the right place, and (2) set up aliases for /snap/bin—although we do have to get some official permission from Snapcraft to enable pnpm and pnpx as globals for the package but that shouldn't be a problem I think.

@revyh
Copy link

revyh commented Apr 24, 2022

Unfortunately, corepack is not the same as a set of preinstalled package managers. It allows users to specify versions of package managers (via the "packageManager" field in package.json) for many projects. So, for example, I can specify [email protected] for package A and [email protected] for package B

@rvagg
Copy link
Member

rvagg commented May 2, 2022

Yeah, sorry, I think https://github.com/nodesource/distributions is going to be a better option for this kind of customisability; attempting to make the Snap more flexible than it is and solve for more bespoke situations is an uphill battle that I don't think we can afford to fight at the moment; if it's even possible. Unless someone has a novel contribution to make here for packing, I think this one is off the table for the Snap.

@igorpupkinable
Copy link

I have tried @rvagg proposed workaround, but it has its own issues.

First: you need to run it as root to be able to write to /usr/local/bin.
Second: check symlink paths. 7222 is the version of a snap. Symlinks will break as soon as you upgrade Node.js snap few times. Ideally it should link to current version of the snap.

sudo -i
PATH=$PATH:/snap/node/current/bin corepack enable --install-directory=/usr/local/bin
ls -Al /usr/local/bin/

lrwxrwxrwx 1 root root 62 Feb 28 11:34 pnpm -> ../../../snap/node/7222/lib/node_modules/corepack/dist/pnpm.js
lrwxrwxrwx 1 root root 62 Feb 28 11:34 pnpx -> ../../../snap/node/7222/lib/node_modules/corepack/dist/pnpx.js
lrwxrwxrwx 1 root root 62 Feb 28 11:34 yarn -> ../../../snap/node/7222/lib/node_modules/corepack/dist/yarn.js
lrwxrwxrwx 1 root root 65 Feb 28 11:34 yarnpkg -> ../../../snap/node/7222/lib/node_modules/corepack/dist/yarnpkg.js

ls -Al /snap/node/
drwxr-xr-x 9 root root 197 Nov  4 21:42 6895
drwxr-xr-x 9 root root 197 Feb 21 22:05 7222
lrwxrwxrwx 1 root root   4 Feb 25 17:44 current -> 7222

I do not see an easy way of getting this working permanently.

@r0gi
Copy link

r0gi commented Mar 7, 2023

I got around this by installing corepack via npm

npm uninstall -g yarn pnpm  # if you somehow had yarn installed via npm
sudo npm install -g corepack

after which

corepack enable

worked fine.

The only caveat is that yarn is still installed via snap, so in order to use yarn via corepack, you must prefix yarn commands with corepack, e.g.

corepack yarn install

On Ubuntu 20.04, node version v18.15.0, npm version 9.5.0

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

No branches or pull requests

5 participants