Two versions of same npm package in Node application

后端 未结 5 982
无人共我
无人共我 2021-01-30 10:34

I\'m working on a CLI tool in NodeJS that uses another NodeJs package that we develop, which is an SDK.

The thing is, we just published a V2 version of that SDK, and we

5条回答
  •  悲&欢浪女
    2021-01-30 11:33

    Based on my answer for a similar question:

    As of npm v6.9.0, npm now supports package aliases. It implements the same syntax as Yarn uses:

    npm install my-sdk-legacy@npm:my-sdk@1
    npm install my-sdk
    

    This adds the following to package.json:

    "dependencies": {
      "my-sdk-legacy": "npm:my-sdk@^1.0.0",
      "my-sdk": "2.0.0"
    }
    

    This seems to me the most elegant solution available, and is compatible with the Yarn solution proposed by @Aivus.

提交回复
热议问题