最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - npm install changes my package-lock.json, will that interfere with the remote code? - Stack Overflow

programmeradmin7浏览0评论

I know there are numerous issues about this, and I discovered the mand npm ci that is supposed to not change package-lock.json, but when I run npm ci it fails:

ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.

Also tried another solution involving deleting my node_modules directory and running npm i again, but that's not changing the oute.

I'm a junior dev working with a team remotely.. I was given a task, so I created a new branch on Gitlab, pulled it down to my local machine and ran npm i to get up-to-speed...

But it keeps changing my package-lock.json DRAMATICALLY(it adds like 20,000 lines of code)

Committing that to the team's project seems insane to me. Anyone have advice?

I know there are numerous issues about this, and I discovered the mand npm ci that is supposed to not change package-lock.json, but when I run npm ci it fails:

ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.

Also tried another solution involving deleting my node_modules directory and running npm i again, but that's not changing the oute.

I'm a junior dev working with a team remotely.. I was given a task, so I created a new branch on Gitlab, pulled it down to my local machine and ran npm i to get up-to-speed...

But it keeps changing my package-lock.json DRAMATICALLY(it adds like 20,000 lines of code)

Committing that to the team's project seems insane to me. Anyone have advice?

Share Improve this question edited Sep 4, 2020 at 13:58 Daniel A. White 191k49 gold badges379 silver badges463 bronze badges asked Sep 4, 2020 at 13:53 Cin88Cin88 5132 gold badges7 silver badges22 bronze badges 2
  • it means they don't agree. – Daniel A. White Commented Sep 4, 2020 at 13:55
  • 2 i'd talk with your team to see exactly what happened and what their process is. – Daniel A. White Commented Sep 4, 2020 at 13:58
Add a ment  | 

2 Answers 2

Reset to default 12

Update: OP wound up needing to make use of yarn which their team and project made use of. If anyone finds a yarn.lock in their project root, this is an indication that yarn is involved and any package-lock.json, if there is one, is possibly outdated.


TL;DR: it sounds like the package-lock.json needs some updates and resolution, which is done primarily with npm install.

It sounds like the package-lock.json no longer "agrees" with your package.json. It also sounds like others on your team are avoiding mitting the changes to your package-lock.json; this is a bad practice in my experience as it only deepens any divergence in their contents. Over time they can be out of sync when dependencies of dependencies may publish a bug fix release and potentially un-publish a previous version.

As a junior dev on this team, I would bring this up to your development/team lead and ask their preferred approach here. If there was a major dependency intentionally removed and that has a lot of its own dependencies, it could cause a large removal of lines from package-lock.json and look severe to one less accustomed to it.

Extra context:

During an install, npm installs the dependencies and development dependencies listed in your package.json. In the process it's possible and increasingly likely over time, that some of the dependencies of those dependencies, which are needed to execute, will overlap and often with conflicting versions. The execution of npm i(nstall) will attempt to reconcile all these peting versions of sub-dependencies for you.

In a Continuous Integration context, it is desirable for the alternate mand npm ci to be used, which explicitly installs only what's resolved already, from package-lock.json (the formerly known as "shrinkwrap"). This is meant to reduce the "but it works on my machine!" moments. As a developer, I've found it to be preferable to use npm install, as this alerts the developers more quickly to any dependency resolution issues and keeps the package-lock.json up to date.

Since this post got so many views I thought I'd e back and post what I found.

Yarn and NPM both update and install packages and dependencies, but the difference is:

yarn creates a file called yarn.lock

npm install creates a file called package-lock.json.

I didn't know this at the time, so when I cloned the project repo to my local machine, I ran npm i which created the package-lock.json. My teammates were already using yarn, however.

So make sure you use the one already being used.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论