volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
11.08k stars 233 forks source link

Global packages doesn't work #1249

Open Rusinas opened 2 years ago

Rusinas commented 2 years ago

Hi! I successfully installed a couple of global packages with Volta and they're displayed in the volta list, but when I try to launch one, I get an error. It looks like this:

PS C:\Users\andre\Desktop> volta list
⚡️ Currently active tools:

    Node: v18.2.0 (default)
    Tool binaries available:
         (default)
         (default)
        nodemon (default)
        npm-check-updates, ncu (default)

See options for more detailed reports by running `volta list --help`.
PS C:\Users\andre\Desktop> ncu       
ncu: The term 'ncu' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\Users\andre\Desktop> nodemon   
nodemon: The term 'nodemon' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\Users\andre\Desktop> 

Interestingly though that I have Volta installed in another user account (for work, in order to use older node.js version globally) and global packages works there just fine.

pls halp

charlespierce commented 2 years ago

Hi @Rusinas, sorry for the delay! You mentioned that Volta works correctly under a different user account. Did you install Volta initially with that other account? There are two pieces to the install:

  1. First, it unpacks the core binary and shims for node, npm, npx, and yarn into the Program Files directory.
  2. Next, it calls volta setup, which configures the appropriate environment variables for the current user.

If you originally installed it under a different user account, you likely don't have that 2nd step set up yet. To fix that, it should be as straightforward as running volta setup under the new user account, which will then set up the Path environment variable. The existing shims (which Volta knows about as you can see from the volta list output) should then start to work because the environment is set up correctly.

Let us know if that doesn't work! I think you're actually the first person we've heard from who's using Volta from multiple accounts on the same Windows machine :smile:

ajcwebdev commented 2 years ago

I recently was having some trouble with global installs as well and wanted to share in case anyone else finds themselves here and need help. When using npm install -g PACKAGE_NAME I received an error. After setting VOLTA_LOGLEVEL to debug I got this message:

[verbose] Unlocking Volta Directory
Volta error: Could not determine the name of the package that was just installed.

Please rerun the command that triggered this error with the environment
variable `VOLTA_LOGLEVEL` set to `debug` and open an issue at
https://github.com/volta-cli/volta/issues with the details!
[verbose] No custom hooks found

I know that the new version of npm handles global installs differently now so I tried npm install --location=global PACKAGE_NAME (which the npm CLI will occasionally tell you to do in v8 but which I can't actually find documentation about on the npm website.). This time it did not error out but the package was still not actually installed. Finally I tried yarn global add PACKAGE_NAME and that seemed to do the trick.

Volta is an amazing tool btw, it's the first thing I download on a new dev machine, so thanks for all the hard work.

astrolemonade commented 2 years ago

I experience the same issue volta version: v1.0.8, same npm-check-updates package. I am using volta from only one account.

korniychuk commented 7 months ago

Reproducible nowadays. Screenshot 2024-03-11 at 21 26 57@2x

tmlmt commented 3 months ago

Confirmed today with v1.1.1 that installing packages globally with npm doesn't work

volta@6d61bdf2bd6c:~$ curl https://get.volta.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10930  100 10930    0     0  37754      0 --:--:-- --:--:-- --:--:-- 37820
  Installing latest version of Volta (1.1.1)
    Checking for existing Volta installation
    Fetching archive for Linux, version 1.1.1
######################################################################## 100.0%
    Creating directory layout
  Extracting Volta binaries and launchers
    Finished installation. Updating user profile settings.
Updating your Volta directory. This may take a few moments...
success: Setup complete. Open a new terminal to start using Volta!
volta@6d61bdf2bd6c:~$ source .bashrc
volta@6d61bdf2bd6c:~$ volta install node@18
success: installed and set node@18.20.4 (with npm@10.7.0) as default
volta@6d61bdf2bd6c:~$ node --version
v18.20.4
volta@6d61bdf2bd6c:~$ volta install npm
success: installed and set npm@10.8.2 as default
volta@6d61bdf2bd6c:~$ npm install -g chalk

added 1 package in 457ms

1 package is looking for funding
  run `npm fund` for details
volta@6d61bdf2bd6c:~$ npm list -g
/home/volta/.volta/tools/image/node/18.20.4/lib
+-- corepack@0.28.0
`-- npm@10.7.0

Will need to stay out of volta for the time being.

robross0606 commented 1 month ago

Confirmed this is still a problem with v2.0.1.
volta list all shows the packages but npm list -g does not:

C:\Code>volta list all
⚡️ User toolchain:

    Node runtimes:
        v14.21.3 (default)
        v18.17.0
        v18.17.1
        v18.18.0
        v18.18.2
        v18.19.0
        v18.19.1
        v18.20.2
        v18.20.3
        v18.20.4 (current @ C:\Code\package.json)
        v20.6.0

    Package managers:
        npm:
            v6.14.18
            v9.8.1
            v10.8.1

    Packages:
        @gitbeaker/cli@39.33.0 (default)
            binary tools: gb, gitbeaker
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in
        clinic@13.0.0 (default)
            binary tools: clinic
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in
        copyright-header@0.4.6 (default)
            binary tools: copyright-header
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in
        cross-env (current @ C:\Code\ncp\study-design-service-hotfix\package.json)
            binary tools: cross-env, cross-env-shell
        depcheck@1.4.7 (default)
            binary tools: depcheck
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in
        i18next-conv@14.1.0 (default)
            binary tools: i18next-conv
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in
        i18next-parser@8.12.0 (default)
            binary tools: i18next
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in
        npm-check-updates@16.14.20 (default)
            binary tools: npm-check-updates, ncu
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in
        semver (current @ C:\Code\package.json)
            binary tools: semver
        why-is-node-running@2.2.2 (default)
            binary tools: why-is-node-running
            platform:
                runtime: node@14.21.3
                package manager: npm@built-in

C:\Code>npm list -g   
C:\Users\user\AppData\Local\Volta\tools\image\node\18.20.4
├── corepack@0.28.0
└── npm@10.7.0

What's interesting is that the globally installed packages do seem to be available for use as long as they include general-use cli scripts. For example:

C:\Code>depcheck
Unused devDependencies
* @nurocor/oss-license-reporter
Missing dependencies
* winston: .\src\logger.js
* axios: .\src\__tests__\index.test.js
* glob: .\src\__tests__\logger.test.js
* @jest/test-sequencer: .\src\__tests__\_test-sequencer.js
* k6: .\k6\loadtest.mjs

However, this is not true of packages which are globally available but only run through node scripting (npx, node exec, etc.).

thilllon commented 1 week ago
VOLTA_BYPASS=1 pnpm list -g