如何在 Visual Studio 2017 中使用 NPM 並安裝包?
我有一個簡單的 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的文件和其他文件。安裝組件的正確方法是什麼?
為避免手動導航到正確的目錄,請使用 Mads Kristensen 的“打開命令行”擴展。它在市場上免費提供。你在這裡找到它。
安裝後,您可以直接從 Visual Studio 中方便地打開命令提示符。
提示:使用鍵盤快捷鍵 ALT+Space 而不是上下文菜單來打開命令提示符。
然後你可以執行你的 npm 命令:
npm install react-bootstrap-typeahead附帶說明:從 npm 5.0.0 開始,已安裝的模組預設添加為依賴項,因此不再需要 –save 選項。
2019 年更新:
開發人員命令提示符和開發人員電源外殼現已集成到 Visual Studio 2019(16.2 預覽版 2)中 - 不再需要擴展。
你在下面找到它們
Tools/Command Line預設情況下沒有分配快捷方式 - 所以你必須自己做。

