How can my module require a specific version of npm?

柔情痞子 提交于 2019-12-23 16:45:52

问题


I am writing an npm module which comes with some scripts, e.g. npm run cureCancer.

I want these scripts to accept extra parameters, which is possible only with npm 2 and above, e.g. npm run cureCancer -- fast

This means that my module depends on npm 2 or newer, so I added the following to package.json:

"devDependencies": {
  "npm": "^2.7.5"
}

Then I ran npm install.

Then I ran npm -v

  • expected: 2.7.5
  • observed: 1.4.23.

And of course npm run cureCancer -- fast fails.

How can my module require a specific version of npm?

As a bonus, I would like npm@2 to be installed locally only, so as not to mess with people's global setup.

UPDATE

Adding npm to the dependencies works, but it doesn't override the global version when using the npm command. To use the locally installed npm instead, use ./node_modules/.bin/npm. This is pretty ugly and unfriendly, so creating an alias might be a good idea.

来源:https://stackoverflow.com/questions/29560416/how-can-my-module-require-a-specific-version-of-npm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!