Skip to content

[BUG] npm install does not honor packages installed with --install-links #5965

Closed

Description

@mlemoine-clgx

Is there an existing issue for this?

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Installing a package with --install-links false, deleting node_modules, then running npm install reinstalls the module as a link and updates package-lock.json

Expected Behavior

npm install should honor and not change package-lock.json, the package should be copied, not linked

Steps To Reproduce

  1. git clone https://github.com/oshi97/install-links.git
  2. cd parent
  3. npm i --no-install-links ../child
  4. ls -l node_modules
  5. cat package-lock.json
  6. rm -Recurse -Force node_modules
  7. npm install
  8. ls -l node_modules
  9. cat package-lock.json

At step 4: d---- 2022-12-14 12:21 PM child

At step 5:

    "node_modules/child": {
      "version": "1.0.0",
      "resolved": "file:../child",
      "license": "ISC"
    }
  },
  "dependencies": {
    "child": {
      "version": "1.0.0"
    }
  }

At step 8: l---- 2022-12-14 12:23 PM child -> <REPO>\child\

At step 9:

 "node_modules/child": {
      "resolved": "../child",
      "link": true
    }
  },
  "dependencies": {
    "child": {
      "version": "file:../child"
    }
  }

Environment

  • npm: 8.19.2
  • Node.js: 18.12.1
  • OS Name: Windows 11
  • npm config:
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v18.12.1
; npm local prefix = <REPO>\parent
; npm version = 8.19.2
; cwd = <REPO>\parent
; HOME = <HOME>

Activity

  1. added
    Bug
    Needs Triage
    Release 8.x
    on Dec 14, 2022
  2. fardolieri commented on Dec 15, 2022

    @fardolieri

    I have a similar problem in npm 9, where I explicitly use npm link to create a symlink to my package. But after running npm install, the symlink disappears and my package is installed again because install-links defaults to true since npm 9. I think it would be great if the config was somehow reflected in the package.json.

    Maybe something like this:

      // package.json
      "dependencies": {
        "my-linked-package": "file:../my-linked-package@link",
        "my-installed-package": "file:../my-installed-package@install"
      }
  3. Sabiil commented on Dec 16, 2022

    @Sabiil

    After updating npm from 8 to 9.2.0 version I can't install local packages with symlinks.

    E.g. I have a local package "react-ui" with some React components.

    When I run command "npm i ../../_packages/react-ui" in other project, I used to have

    "dependencies": {
    ...
    	"react-ui": "file:../../_packages/react-ui",
    ...
    },
    

    section in package.json and this section

    "node_modules/react-ui": {
    	"resolved": "../../_packages/react-ui",
    	"link": true
    },
    

    in package-lock.json.

    Files of "react-ui" package weren't copied to the "node_modules" folder of another project. It was very handy, because I don't have to run update every time I change "react-ui" package.

    But now command "npm i ../../_packages/react-ui" copies all files to the "node_modules" folder of the project.

  4. manuartero commented on Feb 16, 2023

    @manuartero

    @fardolieri :

    the symlink disappears and my package is installed again because install-links defaults to true since npm 9

    But according to [npm docs](the symlink disappears and my package is installed again because install-links defaults to true since npm 9) the default value is false, is this a 'issue' in the documentation itself?

  5. mlemoine-clgx commented on Feb 16, 2023

    @mlemoine-clgx
    Author

    @manuartero

    The default value of --install-links should be used when installing a new package.

    When reinstalling packages based on the package-lock.json (npm install without a package name), I think npm should follow whatever value was specified when the package was installed.

    (I agree that @fardolieri's problem might be a different issue from the original bug)

  6. fardolieri commented on Feb 16, 2023

    @fardolieri

    But according to npm docs the default value is false, is this a 'issue' in the documentation itself?

    It looks like it was changed back last week #6142. That probably fixes my issue. I'll try it out next week and I hopefully don't forget to give you guys an update.

  7. fritzy commented on Mar 1, 2023

    @fritzy

    As you said, we reverted this recently. Please re-open this issue if it is still a problem.

  8. mlemoine-clgx commented on Mar 1, 2023

    @mlemoine-clgx
    Author

    @fritzy
    This revert did not fix the issue:

    C:\Users\mlemoine\tmp\install-links\parent> npm --version
    9.5.0
    C:\Users\mlemoine\tmp\install-links\parent> npm i --no-install-links false ..\child\
    
    added 1 package, and audited 2 packages in 399ms
    
    found 0 vulnerabilities
    C:\Users\mlemoine\tmp\install-links\parent> ls .\node_modules\
    
        Directory: C:\Users\mlemoine\tmp\install-links\parent\node_modules
    
    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    d----          2023-03-01  3:33 PM                child
    -a---          2023-03-01  3:33 PM            228 .package-lock.json
    
    C:\Users\mlemoine\tmp\install-links\parent> rm -Recurse -Force .\node_modules\
    C:\Users\mlemoine\tmp\install-links\parent> npm i
    
    added 1 package, and audited 3 packages in 358ms
    
    found 0 vulnerabilities
    C:\Users\mlemoine\tmp\install-links\parent> ls .\node_modules\
    
        Directory: C:\Users\mlemoine\tmp\install-links\parent\node_modules
    
    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    l----          2023-03-01  3:33 PM                child -> C:\Users\mlemoine\tmp\install-links\child\
    -a---          2023-03-01  3:33 PM            267 .package-lock.json
    
    C:\Users\mlemoine\tmp\install-links\parent>
    

    Please note that for npm to install the package as a copy and not a link, we need to specify --no-install-links false which is very unintuitive and probably a bug as well!

    I expect the latest npm i to reinstall the package exactly the way it was originally installed.

  9. tallero commented on Mar 4, 2025

    @tallero

    I'd like to report that as of today with npm version 11 if I do run

    npm \
      --install-links="false" \
      install \
        <directory>
    

    npm keeps installing a link instead than copying the directories over.

    I have no idea I should be supposed to actually install the packages instead of creating links, except than directly copying the packages into the node_modules directory.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageRelease 8.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions