如何在 Visual Studio 2017 中使用 NPM 并安装包?

How to use NPM and install packages inside Visual Studio 2017?(如何在 Visual Studio 2017 中使用 NPM 并安装包?)
本文介绍了如何在 Visual Studio 2017 中使用 NPM 并安装包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

npm install --save react-bootstrap-typeahead

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

我的结果:

当我运行它时,我得到以下很好的错误,这显然是有道理的.如果 NPM 认为它可以在 'C:UsersLarsHoldgaardpackage.json' 处找到我的项目文件,那就不走运了.正确的路径是 C:UsersLarsHoldgaardDocumentsGithubLikvido.CreditRiskLikvido.CreditRiskLikvido.CreditRisk.

npm : npm WARN saveError ENOENT: 没有这样的文件或目录,打开 'C:UsersLarsHoldgaardpackage.json'在行:1 字符:1+ npm install --save react-bootstrap-typeahead+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (npm WARN saveEr...dpackage.json':String) [], RemoteException+ FullyQualifiedErrorId : NativeCommandErrornpm警告恩恩ENOENT:没有这样的文件或目录,打开 'C:UsersLarsHoldgaardpackage.json'npm警告grunt-sass@2.0.0 需要 grunt@>=0.4.0 的对等点,但没有安装.您必须自己安装对等依赖项.npm警告react-rating@1.0.6 需要一个 react@>=0.13.0 的对等体,但没有安装.您必须自己安装对等依赖项.npm警告react-bootstrap-typeahead@2.5.1 需要一个 react@^0.14.0 ||^15.2.0 ||^16.0.0 但没有安装.您必须自己安装对等依赖项.npm警告react-bootstrap-typeahead@2.5.1 需要一个 react-dom@^0.14.0 ||^15.2.0 ||^16.0.0 但没有安装.您必须自己安装对等依赖项.npm警告prop-types-extra@1.0.1 需要 react@>=0.14.0 的对等体,但没有安装.您必须自己安装对等依赖项.npm警告react-overlays@0.8.3 需要一个 react@^0.14.9 ||>=15.3.0 但没有安装.您必须自己安装对等依赖项.npm警告react-overlays@0.8.3 需要一个 react-dom@^0.14.9 ||>=15.3.0 但没有安装.您必须自己安装对等依赖项.npm警告react-onclickoutside@6.7.1 需要一个 react@^15.5.x ||^16.x 但没有安装.您必须自己安装对等依赖项.npm警告react-onclickoutside@6.7.1 需要 react-dom@^15.5.x 的 peer ||^16.x 但没有安装.您必须自己安装对等依赖项.npm警告react-transition-group@2.2.1 需要一个 react@>=15.0.0 的对等体,但没有安装.您必须自己安装对等依赖项.npm警告react-transition-group@2.2.1 需要一个 react-dom@>=15.0.0 的对等体,但没有安装.您必须自己安装对等依赖项.npm警告LarsHoldgaard 没有描述npm警告LarsHoldgaard 没有存储库字段.npm警告LarsHoldgaard 没有 README 数据npm警告LarsHoldgaard 没有许可证字段.

我的想法:

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

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

解决方案

为避免手动导航到正确的目录,请使用 Mads Kristensen 的打开命令行"扩展.它在市场上免费提供.您可以在

提示:使用键盘快捷键 ALT+Space 而不是上下文菜单来打开命令提示符.

然后你可以运行你的 npm 命令:

npm install react-bootstrap-typeahead

附带说明:从 npm 5.0.0 开始,已安装的模块默认添加为依赖项,因此不再需要 --save 选项.

2019 年更新:

开发人员命令提示符和开发人员 Power Shell 现在已集成到 Visual Studio 2019(16.2 预览版 2)中 - 不再需要扩展.

您可以在 Tools/Command Line

下找到它们

默认情况下没有分配快捷方式 - 所以你必须自己做.

I have a simple Visual Studio solution, running ASP.NET Core v2 and building a React app.

Now, I want to install a simple component using the NPM. In this particular example, it could be:

npm install --save react-bootstrap-typeahead

I want this package to work just in my solution and nowhere else.

My result:

When I run this, I get the following nice error which obviously makes some sense. If NPM believes it can find my project file at 'C:UsersLarsHoldgaardpackage.json', it's out of luck. The correct path would be C:UsersLarsHoldgaardDocumentsGithubLikvido.CreditRiskLikvido.CreditRiskLikvido.CreditRisk .

npm : npm WARN saveError ENOENT: no such file or directory, open 'C:UsersLarsHoldgaardpackage.json'
At line:1 char:1
+ npm install --save react-bootstrap-typeahead
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (npm WARN saveEr...dpackage.json':String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

npm

WARN

enoent
 ENOENT: no such file or directory, open 'C:UsersLarsHoldgaardpackage.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:

Being a console noob, I would guess I just needed to change my current folder. But if I run dir, I am in the right folder, and I can see my package.json along with other files.

What is the right way to install components?

解决方案

To avoid navigating manually to the correct directory use the "Open Command Line" extension from Mads Kristensen. It is available for free in the Marketplace. You find it here.

Once installed you can open a command prompt conviently directly from within Visual Studio.

Tipp: Use the Keyboard Shortcut ALT+Space instead of the context menu to open the command prompt.

You can then run your npm command:

npm install react-bootstrap-typeahead

As a side note: As of npm 5.0.0, installed modules are added as a dependency by default, so the --save option is no longer required.

Update 2019:

Developer Command Prompt and Developer Power Shell are now integrated into Visual Studio 2019 ( 16.2 Preview 2 ) - no need for an extension anymore.

You find them under Tools/Command Line

By default no shortcut is assigned - so you have to do this yourself.

这篇关于如何在 Visual Studio 2017 中使用 NPM 并安装包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
How to Create such a Task Panel?(如何创建这样的任务小组?)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)