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

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

npm install --save react-bootstrap-typeahead

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

My result:

当我运行这个程序时,我得到了下面的错误,这显然是有道理的.如果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.

My thinking:

作为一个console noob岁的人,我想我只需要更改我当前的文件夹.但是如果我运行dir,我在正确的文件夹中,我可以看到我的package.json和其他文件.

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

推荐答案

要避免手动导航到正确的目录,请使用MADS Kristensen的"Open Command Line"扩展.它在市场上是免费的.你会发现它是here.

安装后,您可以直接在Visual Studio中方便地打开命令提示符.

enter image description here

提示:使用键盘快捷键Alt+空格键(而不是关联菜单)打开命令提示.

然后可以运行npm命令:

npm install react-bootstrap-typeahead

附注:从NPM 5.0.0开始,默认情况下,已安装的模块作为依赖项添加,因此不再需要--save选项.

Update 2019:

开发者命令提示符和开发者Powershell现在集成到VisualStudio2019(16.2预览版2)中,不再需要扩展.

你发现他们在Tools/Command Line岁以下

默认情况下没有分配快捷键,因此您必须自己执行此操作.

enter image description here

Asp.net相关问答推荐

Razor页面上@Foreach的正确语法,其中值可以等于多个值

.Net Framework:w3wp.exe 中的异常

无法加载文件或程序集.无效指针(HRESULT 异常:0x80004003 (E_POINTER))

如何将配置转换应用于外部配置文件

如何使用三个按钮是否和取消显示确认alert ,如 MS Word 中所示

如何在不使用 Session 的情况下在 ASP.net 中的页面之间传递值

如何从 URI 中删除 PROTOCOL

页面在谷歌浏览器中加载两次

如何从 Asp.net Mvc-3 发送邮箱?

跟踪点有什么用途?

解析器错误:无法创建类型

GMT 和 UTC 一样吗?

svg 无法在 localhost 上的 IIS 网络服务器上运行

您正在使用哪些身份验证和授权方案 - 为什么?

头标记中的内联代码 - ASP.NET

如何将 GridView.DataSource 导出到数据表或数据集?

ASP.NET 核心,更改未经授权的默认重定向

如何从 ASP.NET Identity 获取用户列表?

POST 字符串到 ASP.NET Web Api 应用程序 - 返回 null

为什么调试器不会在我的 ASP.NET 应用程序的断点处停止?