How do I prevent npm install from removing packages?

后端 未结 5 1232
无人及你
无人及你 2021-01-11 15:39

I\'m trying to set up a development environment with several packages, and as a result I need to manually install some dependencies. More specifically, I have some local ch

相关标签:
5条回答
  • 2021-01-11 16:02

    Are you saving the dependencies to package.json? To Save : npm install --save {package_name}. This will save the package to package.json and install using npm install.

    You can't particularly control the dependencies(fully). The dependencies which you have installed might be using dependencies themselves.So when you remove a package, npm deletes all the package's dependencies and the package.

    0 讨论(0)
  • 2021-01-11 16:09

    If your development flow involves updating in parallel packages which depend on one another, you might consider switching your project's package manager to from npm to yarn to take advantage of yarn's workspaces feature.

    Yarns's workspaces allow you to easily setup a single monorepo containing all your interconnected dependencies, and let yarn thinking how to link them together in your dev environment.

    0 讨论(0)
  • 2021-01-11 16:14

    i had a similar problem today , & thought this might help someone in the future and l have found out that if you install simultaneouly it

    npm install --save package1 package2 package3 ...

    it worked as l had

    npm install xlsx angular-oauth2-oidc

    but if you install separately it will have issues

    Edit 2 More infor by @Michael

    installing multiple packages in the same command also prevents hooks from being installed multiple times

    0 讨论(0)
  • 2021-01-11 16:15

    Just Use Yarn to install package instead of using npm while installing packages

    yarn add package-name
    
    0 讨论(0)
  • 2021-01-11 16:26

    Have a look at npm link if you need to test against modified packages.

    From npm link: This is handy for installing your own stuff, so that you can work on it and test it iteratively without having to continually rebuild.

    Say b is a dependency of a. You made changes to b and want to check if a still works with those changes. Instead of using b in node_modules installed from npm, use your local, modified version:

    cd ~/projects/b    # go into the package directory
    npm link           # creates global link
    cd ~/projects/a    # go into some other package directory.
    npm link b         # link-install the package
    

    Now, any changes to ~/projects/b will be reflected in ~/projects/a/node_modules/b/.

    0 讨论(0)
提交回复
热议问题