gpt4 book ai didi

asp.net - 如何在 Visual Studio 2017 中使用 NPM 并安装包?

转载 作者:行者123 更新时间:2023-12-03 13:44:50 26 4
gpt4 key购买 nike

我有一个简单的 Visual Studio 解决方案,运行 ASP.NET Core v2 并构建一个 React 应用程序。

现在,我想使用 NPM 安装一个简单的组件。在这个特定的例子中,它可能是:

npm install --save react-bootstrap-typeahead

我希望这个包只在我的解决方案中工作,而不是在其他地方工作。

我的结果:

当我运行它时,我得到以下很好的错误,这显然是有道理的。如果 NPM 认为它可以在 'C:\Users\LarsHoldgaard\package.json' 找到我的项目文件,运气不好。正确的路径是 C:\Users\LarsHoldgaard\Documents\Github\Likvido.CreditRisk\Likvido.CreditRisk\Likvido.CreditRisk .
npm : npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\LarsHoldgaard\package.json'
At line:1 char:1
+ npm install --save react-bootstrap-typeahead
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (npm WARN saveEr...d\package.json':String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

npm

WARN

enoent
ENOENT: no such file or directory, open 'C:\Users\LarsHoldgaard\package.json'

npm

WARN
grunt-sass@2.0.0 requires a peer of grunt@>=0.4.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
react-rating@1.0.6 requires a peer of react@>=0.13.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
react-bootstrap-typeahead@2.5.1 requires a peer of react@^0.14.0 || ^15.2.0 || ^16.0.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
react-bootstrap-typeahead@2.5.1 requires a peer of react-dom@^0.14.0 || ^15.2.0 || ^16.0.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
prop-types-extra@1.0.1 requires a peer of react@>=0.14.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
react-overlays@0.8.3 requires a peer of react@^0.14.9 || >=15.3.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
react-overlays@0.8.3 requires a peer of react-dom@^0.14.9 || >=15.3.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
react-onclickoutside@6.7.1 requires a peer of react@^15.5.x || ^16.x but none is installed. You must install peer dependencies yourself.

npm

WARN
react-onclickoutside@6.7.1 requires a peer of react-dom@^15.5.x || ^16.x but none is installed. You must install peer dependencies yourself.

npm

WARN
react-transition-group@2.2.1 requires a peer of react@>=15.0.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
react-transition-group@2.2.1 requires a peer of react-dom@>=15.0.0 but none is installed. You must install peer dependencies yourself.

npm

WARN
LarsHoldgaard No description

npm

WARN
LarsHoldgaard No repository field.

npm

WARN
LarsHoldgaard No README data

npm

WARN
LarsHoldgaard No license field.

我的想法:

作为 控制台菜鸟 ,我想我只需要更改我当前的文件夹。但是如果我运行 dir ,我在正确的文件夹中,我可以看到我的 package.json连同其他文件。

安装组件的正确方法是什么?

最佳答案

我认为最简单的方法是简单地使用 Visual Studio 提供的 UI。

在项目的根目录中创建 package.json (这样做,右键单击您的项目,添加项目并搜索 NPM 。您将找到 npm Configuration File ):

{
"name": "SomeName",
"version": "1.0.0",
"private": true,
"devDependencies": {
"react-bootstrap-typeahead": "*"
}
}

请注意 *适用于最新版本。不建议这样做。最好指定您想要的版本。您会注意到,您支持版本和包名称的智能。

每次更改 json 文件时,只需按 CTRL + S。Visual Studio 会自动调用 NPM 并恢复包。

对于如何使用命令行,其他人已经回答了。但作为一个命令行菜鸟,我更喜欢这种方式。

关于asp.net - 如何在 Visual Studio 2017 中使用 NPM 并安装包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49208056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com