How to use NPM and install packages inside Visual Studio 2017? - asp.net

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:\Users\LarsHoldgaard\package.json', it's out of luck. The correct path would be 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:
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.

I think the easiest way is to simple use the UI, Visual Studio provides.
Create in the root of your project a package.json (Todo so, right click your project, add item and search for NPM. You will find a npm Configuration File):
{
"name": "SomeName",
"version": "1.0.0",
"private": true,
"devDependencies": {
"react-bootstrap-typeahead": "*"
}
}
Note that * is for the latest version. This is not recommended. Better to specify the version you want. You will notice, that you have support of intellisence for versions and package names.
Everytime you make changes to the json file, simple press CTRL + S. Visual Studio automaticly calls NPM and restores the packages.
For how to use the command line, other have already answerd. But as being a command line noob myself, I prefer this way.

You can use the Package Manager Console to run npm command.
To open the Package Manager Console, go to Tools > Nuget Package Manager and select Package Manager Console and then enter your npm command.
Update:
The latest visual studio 16.8.3 onwards, you will find the terminal built into visual studio.
You can find it by right-clicking at your solution or a shortcut Ctrl + `:

In Window's Explorer, navigate to where the package.json file is located in your project.
Create a folder named node_modules in the same directory as your package.json file
While holding the left [Shift] key, right click in the folder containing the project.json file.
From the context menu select 'Open command window here'.
Input your npm command npm install --save react-bootstrap-typeahead

I use a different approach, configuring npm per SOLUTION, instead of per PROJECT.
Please refer to my BLOG:
A better way to use Visual Studio with npm ( and Gulp )
It is working fine and you may use Command Line ou Package Manager Console do install/update/uninstall npm packages.
I am currently using it with Visual Studio 2019 and ASP.NET Core MVC.

Adding my 2 cents from 2021.
Visual Studio comes with built-in npm support, no CLI required. VS can automatically install/restore packages in the background - on project open and/or after making changes to packages.json file. You can enable this here:
For example, here's an article about configuring automatic minification and compilation for js/css files via npm tool, using just naked Visual Studio (DISCLAIMER: I wrote that blog post myself last year)

Related

Something went wrong installing JavaScript dependencies, check your npm logfile or run npm install again manually [duplicate]

I am using react native and Expo. I am unable to build new app because after I use expo init appName it shows the following error.
Heres the full message:
📦 Using npm to install packages. You can pass --yarn to use Yarn instead.
√ Downloaded and extracted project files.
× Something when wrong installing JavaScript dependencies. Check your npm logs. Continuing to initialize the app.
✅ Your project is ready!
To run your project, navigate to the directory and run one of the following npm commands.
- cd Scanner
- npm start # you can open iOS, Android, or web from here, or run them directly with the commands below.
- npm run android
- npm run ios # requires an iOS device or macOS for access to an iOS simulator
- npm run web
I tried multiple times to create a blank project, also tried npm install to install failed/not downloaded libraries and continue after failure but it showed another error:
npm ERR! code Z_BUF_ERROR
npm ERR! errno -5
npm ERR! zlib: unexpected end of file
also tried npm cache verify that showed cache is ok Content verified: 3562 (252580364 bytes).
So, How can I solve this issue?
Problems related to npm installation are very common If you do any mistake in early installation, but is avoided. Learn more about npm tree.
Steps worked for me are :
npm cache clean --force
npm cache verify
npm -g uninstall expo-cli --save
npm install expo-cli --global
expo init app-name
cd app-name
npm start
Always run as administrator if working on Windows and in root directory.
The solutions above didn't work for me but if you use 'npm install' in the directory of the app you get a clue that you shuold try 'npm install --force'
err message
You should have all these files folders and files at the start of the project otherwise not all the dependencies have been installed which is why we were getting the problem.folder structure
After you have added --force to npm install you have all the dependencies installed. Now you can run the app with npm start.
Unfortunately, all the solutions described above didn't work on my machine...
Here is my latest solution for this problem...
This worked 100% on my machine...
Use npm i -g expo-cli
This will automatically add the required packages and also remove the unnecessary ones.
Yes, surely, you don't need to uninstall and re-install it again.
Just follow my steps.
And, you can create your expo project using expo init.
I hope my solution will help you out from this annoying problem....
I just did npm install and it worked for me, but I had do that every time I create a new expo project.
I also encountered this problem, and finally found that it was the problem of react native cli,I installed the latest version of react native cli,Expo is back to normal
This Error is regarding to the git account. expos need a git account to setup react native project
If you are using windows you need to install git in your local PC
after that open your Terminal and type this command
git config --global user.name "your_username"
git config --global user.email "your_email_address#example.com"
after that clone any github project to your local computer. it will ask to login to Github
after all these steps try expo init <projectname>
The simple way to settle that error is by using "expo-cli init app-name" instead of "expo init app-name".
I tried and worked perfectly for me. Hope it will help you guys.
i have faced a similar problem and running yarn set version 1.22.1 fix it
Run the Command Prompt as an administrator. And run the following command:
npx create-expo-app AwesomeProject

Cannot download "https://github.com/sass/node- sass/releases/download/v4.5.2/darwin-x64-57_binding.node" error. What does this mean?

I've created used Meteor to create an APP that communicates with some hardware through MQTT using Mosquitto. It was done on a Linux computer and everyone went fine. Now I've loaded the files onto OSX and I'm getting the following error with it. I've tried updates sass to the latest verson and then redoing npm install, but to no avail.
=> A patch (Meteor 1.7.0.5) for your current release is available!
Update this project now with 'meteor update --patch'.
Errors prevented startup:
While loading package materialize:materialize#0.100.2:
error: Command failed: /Users/random/.meteor/packages/meteor- tool/.1.7.0_4.x53m8m.ifru9++os.osx.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.osx.x86_64/dev_bundle/bin/npm rebuild --update-binary
Cannot download "https://github.com/sass/node- sass/releases/download/v4.5.2/darwin-x64-57_binding.node": HTTP error 404 Not Found
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.
export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080
I have found a solution.
Remove the node_modules folder
Remove the package-lock.json file
Clear npm cache with
npm cache clean
Install the last version
npm install node-sass#latest
npm rebuild node-sass
Modify package.json from your project to new version of node-sass
Run
npm i
If you have another dependency that use node-sass change her version
Remove package-lock.json then npm install, again. Worked for me.
(No need to remove node modules)

Meteor 1.7 bundler is broken

I am trying to deploy an app that has been upgraded to meteor 1.7 using the setup for passenger outlined at puhsionpasserger.com, however when I try and access the app I get an error in the console of
Error: The core-js npm package could not be found in your node_modules directory. Please run the following command to install it: meteor npm install --save core-js
Being shown on the web page (although the favercon is correct so its trying).
The app runs fine locally (as in on the dev machine).
Give its deployed, meteor doesn't exist on the machine.
I tried npm install --save core.js and it reported one package installed, but still no joy on the app front.
I'm not sure where to go from here. Any thoughts?
Edit:
I just tried building the app without the --server-only flag with no change. Deployed the app the way I do with the v1.3 instances of the app and no change.
One thing that I did get when running npm intall from the /programs/server directory was
Binary is fine; exiting
npm WARN lifecycle meteor-dev-bundle#~install: cannot run in wd %s %s (wd=%s) meteor-dev-bundle# node npm-rebuild.js /opt/bundle/programs/server
added 131 packages in 13.857s
I'm not sure if the warning means anything in particular.

Meteor 1.3 node build: doesn't work anymore with React

With 1.2.*, I used to build my staging/production bundles with meteor build, then moving into ./bundle/programs/server and npm install there.
I do the same thing with 1.3 version but now I have error message on trying to run bundle main file with node:
WARNING: npm peer requirements not installed:
- react#0.14.x not installed.
- react-addons-pure-render-mixin#0.14.x not installed.
Read more about installing npm peer dependencies:
http://guide.meteor.com/using-packages.html#peer-npm-dependencies
/var/www/builds/1459320997/bundle/programs/server/node_modules/fibers/future.js:267
throw(ex);
^
Error: Can't find npm module 'react'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
I use react-meteor-data meteor package.
However, I already have "react": "^0.14.8", and "react-addons-linked-state-mixin": "^0.14.8", in my package.json and of course installed it with npm install ... --save and it is working fine on development environment when I use meteor command.
Any additional actions needed to run it? Did they change how meteor package should be build for production and didn't changed their docs? (because I don't see any changes in docs concerning meteor build so far.
Update: I tried to manually npm install these packages into ./bundle/program/server. Now they consequentially requires packages already listed in my package.json. I suppose Meteor just ignore this file on bundle. Will try to add a bug in their tracker.
I used Meteor 1.2 to build new 1.3 code so it is the issue. It happened because currently I build on the server that had another Meteor version.
I used answer from another Stackoverflow user (Ian) Updating all Meteor packages to latest versions
Easiest way is to delete the contents of .meteor/versions and then save

Installing natural package in a meteor application

For having natural language processing facility. Have added natural node package in my application using "npm install natural". But after installation while running the application using "sudo meteor", got some error about ""ReferenceError: require is not defined"". After googling found that need to do following steps:
1) Remove node_modules on the top of the root of the application (Done this part)
2) Added "natural": "0.1.27" in packages.json file also
3) Install npm using ""mrt add npm"". But getting following error after installing it in the application, while using ""sudo meteor"".
=> Meteor 0.8.1.3 is available. Update this project with 'meteor update'.
Initializing mongo database... this may take a moment.
npm ERR! missing: rimraf#2.x, required by meteor-npm#0.1.10
npm ERR! missing: mkdirp#0.3.x, required by meteor-npm#0.1.10
npm ERR! not ok code 0
=> Errors prevented startup:
While building package router:
error: no such package: 'ui'
While building package npm:
error: couldn't read npm version lock information
=> Your application has errors. Waiting for file change.
Any pointers what should be done. Not getting anything, this error taking my whole time. Thanks in advance
To use NPM packages within your meteor application you need to first install meteor-npm
mrt add npm
You then have to add a packages.json file at the root of your project like so;
{
"natural": "0.1.27"
}
When this file changes, meteor will automatically update its dependencies.
You can then use var natural = Meteor.require("natural")

Resources