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

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

Closed
2 tasks done
mlemoine-clgx opened this issue Dec 14, 2022 · 7 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@mlemoine-clgx
Copy link

mlemoine-clgx commented Dec 14, 2022

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>
@mlemoine-clgx mlemoine-clgx added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Dec 14, 2022
@fardolieri
Copy link

fardolieri commented Dec 15, 2022

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"
  }

@Sabiil
Copy link

Sabiil commented Dec 16, 2022

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.

@manuartero
Copy link

@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?

@mlemoine-clgx
Copy link
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)

@fardolieri
Copy link

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.

@fritzy
Copy link
Contributor

fritzy commented Mar 1, 2023

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

@fritzy fritzy closed this as completed Mar 1, 2023
@mlemoine-clgx
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

5 participants