jquery
,您只需发布名为 jquery-alias1
、jquery-alias2
、jquery-alias3
等软件包,然后在 package.json
中设置相应的版本。
或者,您可以根据其版本号命名软件包,例如 jquery-1.11.x
、jquery-2.1.x
等。
虽然这两种方法似乎有些粗糙。有更好的方法吗?jquery
,您只需发布名为 jquery-alias1
、jquery-alias2
、jquery-alias3
等软件包,然后在 package.json
中设置相应的版本。
或者,您可以根据其版本号命名软件包,例如 jquery-1.11.x
、jquery-2.1.x
等。
虽然这两种方法似乎有些粗糙。有更好的方法吗?自v6.9.0起,npm支持包别名,并实现了与Yarn相同的语法:
npm install jquery2@npm:jquery@2
npm install jquery3@npm:jquery@3
这将添加以下内容到 package.json
文件中:
"dependencies": {
"jquery2": "npm:jquery@^2.2.4",
"jquery3": "npm:jquery@^3.4.1"
}
也可以直接从GitHub安装。例如,如果你想要同时安装npm注册表版本和foobar
的GitHub分支:
npm install foobar
npm install foobar-fork@github:username/foobar
eslint
,但不知道它现在被命名为 eslint6
。 - Crimbo我想在这里发布一些信息,特别是像我这样正在使用 Yarn 且来到这里的人。它是 NPM 的一个更或多或少的替代品,并且原生支持别名:
yarn add material-ui@latest
yarn add material-ui-next@npm:material-ui@next
then
import FlatButton from 'material-ui/FlatButton'; // v0.x
import Button from 'material-ui-next/Button'; // v1.x
(该示例的来源请见https://github.com/callemall/material-ui/issues/7195#issuecomment-314547601)
<alternative-name>@npm:<package-name>@<version>
。 - katsosyarn add react-bootstrap4@npm:react-bootstrap@1.5.1
,但是 React Webpacker 抱怨找不到模块 react-bootstrap4
。然而,yarn add react-bootstrap-next@npm:react-bootstrap@1.5.1
却完美地工作了。 - new2cpp$ jspm install jquery
... (status msgs) ...
ok Installed jquery as github:components/jquery@^2.1.4 (2.1.4)
$ jspm install jqueryOne=jquery@1.11.3
... (status msgs) ...
ok Installed jqueryOne as github:components/jquery@1.11.3 (1.11.3)
github:components/jquery 1.11.3 2.1.4
然后在你的js中,你可以简单地require(jquery)
和/或require(jqueryOne)
,如果需要的话,允许你根据需要来回切换。
对于任何你想使用多个版本的包,都适用这个方法。
我不是npm的专家,但我有以下问题:两个依赖项在争夺一个版本。 我提供一个例子,因为对于初学者来说很难理解。
我在package.json中定义了以下两个依赖项:
"@ngtools/webpack": "^13.2.2",
"angular-named-lazy-chunks-webpack-plugin": "^2.1.0",
他们都需要webpack的一个版本,但是不同的版本。他们之间存在竞争关系。你的评论和解决方案对我很有帮助,因为我在devDependencies中定义了以下内容:
"webpack5": "npm:webpack@^5.68.0",
"webpack4": "npm:webpack@^4.46.0",
现在,"@ngtools/webpack" 和 "angular-named-lazy-chunks-webpack-plugin" 都很满意。 webpack5 和 webpack4 的名称是随机的。我猜你可以使用任何你喜欢的名称。
错误是:
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: openpaas-ssp@0.0.0
npm ERR! Found: webpack@4.46.0
npm ERR! node_modules/webpack
npm ERR! dev webpack@"^4.46.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^5.30.0" from @ngtools/webpack@13.2.2
npm ERR! node_modules/@ngtools/webpack
npm ERR! dev @ngtools/webpack@"^13.2.2" from the root project
当我为webpack设置5.30时,"@ngtools/webpack"已经被满足,但我仍然从"angular-named-lazy-chunks-webpack-plugin"中获得了类似的错误。
我需要安装react-table新版本7,而我之前全局安装的是旧版本6。因此,我们面临一个问题,在应用程序中需要使用新版本表格进行新开发,但不能破坏旧表格的功能,所以我安装了两个带有不同关键字的表格。
例如:
require
:
var multidepPackages = require('multidep')('test/multidep.json');
var jquery1 = multidepRequire('jquery', '1.11.3');
var jquery2 = multidepRequire('jquery', '2.1.4');
npm init
在设置了这个shell package.json之后,我安装了我需要的确切版本的create-react-app。
npm install create-react-app@1.5.2
这个操作会在本地创建一个node_modules文件夹,并包含旧版本的create-react-app。
之后我创建了一个名为create-react-app.sh的简单bash脚本,作为访问旧版本的快捷方式,并使用bash变量"$@"来转发所有参数:
#!/bin/bash
{full-directory-path}/node_modules/create-react-app/index.js "$@"
最后,我使这个简单的bash脚本可执行。
chmod u+x create-react-app.sh
直接运行此bash脚本将执行旧版本的create-react-app:
./create-react-app.sh --version
1.5.2
react-native-reanimated
v2.10.0 和 v3.1.0 版本,能帮忙吗? - famfamfam"graphql": "^15.8.0 || ^16.6.0 || ^15.3.0",
你需要运行 npm install。
NPM Install Version (https://github.com/scott113341/npm-install-version) 是另一个选择。它本质上与这里的其他解决方案做的事情相同(从技术角度讲),但使用起来非常简单。使用版本号(NPM使用的标准@version命令参数)安装的模块会被预测性地安装在名为该名称的子文件夹下的node_modules文件夹中。您还可以控制每个模块的目标目录-这对于构建系统非常有用。
来自GitHub文档的使用代码片段:
const niv = require('npm-install-version');
const benchmark = require('./some-benchmark-function.js');
niv.install('csjs@1.0.0');
// installs csjs@1.0.0 to node_modules/csjs@1.0.0/
niv.install('csjs@1.0.1');
// installs csjs@1.0.1 to node_modules/csjs@1.0.1/
const csjs_old = niv.require('csjs@1.0.0');
const csjs_new = niv.require('csjs@1.0.1');
// require the old and new versions of csjs
benchmark([csjs_old, csjs_new], 'some-test-input');
// run our fake benchmark function on the old and new versions of csjs