I already installed an npm library, how do I add it to my package.json dependencies?? - npm

I already installed an npm library. When installing I forgot to add the "-save" flag. How do I add the library to the package.json dependencies?

you can manually add the specific dependency as below:-
example(package.json):-
"react": "^15.6.1"
if you don't know the version of the library you're going to install, just do the install again on project path as below:
npm i react -S
This will add stable version automatically to package.json. Hope this helps.

You can run the command:
npm install react --save
or
npm install react --save-dev

Related

Globally installation of packages with npm

I have a question regarding the package manager npm and the meaning of installing the package globally.
For example I work often with react, should I install react globally?
npm install -g react react-dom
Does this mean that next time when I do
npx creat-react-app my-app
It will get the package from the global or it does not matter and it will still download it locally inside my-app?
Because I really do not understand the idea behind installing globally.
Because if I want to use a package it should be mentioned in package.json, if it is in package.json it is then located in node_module ... so yeah ...
Could anyone give me better insight?
Thanks in advance
React library can be installed globally on your local machine. In development there is no real reason to do that since you might not have the latest version and this might cause issues.
Better practise is to use react on project level by using the command you stated above npx create-react-app my-app
If you push code to a server the package.json file will install the dependencies (React, React DOM,..) to build your project.
Read more here : https://create-react-app.dev/docs/getting-started/
If you've previously installed create-react-app globally via npm
install -g create-react-app, we recommend you uninstall the package
using npm uninstall -g create-react-app or yarn global remove
create-react-app to ensure that npx always uses the latest version.
You can check what packages are installed globally using:
npm list -g --depth 0

How to remove unwanted expo modules

When creating an react native app with expo, expo installs many module that i don't need. Is there a way to remove these unwanted modules like barcode reader google sign in and google maps.
thanks
To remove a package from your node_modules directory, on the command line, use the uninstall command. Include the scope of the package is scoped.
Unscoped package
npm uninstall --save <package_name>
Scoped package
npm uninstall --save <#scope/package_name>
if need to know more about it then follow official Document here https://docs.npmjs.com/uninstalling-packages-and-dependencies#removing-a-local-package-from-the-packagejson-dependencies
npm uninstall <package name> works. It removes the expo module from your node_modules
for more reference
https://docs.npmjs.com/uninstalling-packages-and-dependencies
With NPM
$ npm uninstall jest
Shorthand version
$ npm r jest
With Yarn
$ yarn remove jest

Install Expo package directly from Github

For some reason the Expo team is not updating their packages on npm and I need to install directly from their Github repo. The packages are in the packages/package-name folders on the main Expo repository.
I put "expo-blur": "expo/expo packages/expo-blur" in package.json, but that also just uses the npm release. I asked a similar question here: https://forums.expo.io/t/recommended-way-for-using-expo-packages-straight-from-github/22022.
What do I need to put in package.json so that it uses the code from here: https://github.com/expo/expo/tree/master/packages/expo-blur ?
No you can't. You will end up having it undefined in your package.json file like this:
The command was:
npm install Teknasyon-Teknoloji/desk360-react-native-sdk#1.0.0 --save
I tried:
npx expo install Teknasyon-Teknoloji/desk360-react-native-sdk#1.0.0
So the correct way is:
Switch to bare workflow if you are in managed workflow:
npx expo prebuild
Then follow the rest of the steps from the package docs. So I then ran:
npm install Teknasyon-Teknoloji/desk360-react-native-sdk#1.0.0 --save
then cd ios, pod install ...etc.

How to update package.json dependencies when linking from globally installed packages?

I organize my development projects installing globally all the npm packages I need with:
npm -g install [package]
Then I simlink individually the dependencies I need for each project with:
npm link [package]
This way, I have to update manually each package.json file to add the dependency, and when I upgrade the global node_modules I have to go and update all the package.json projects.
For this first issue I tried npm link [package] --save but it doesn't add the dependency to package.json and if I use npm install [package] --save it installs the package locally, thing I don't want.
Is there any way to be able to not have to configure package.json manually and be able to have an updated configuration of package.json from many different projects in a easier way?
Yes you can install npm-check-updates, you can find the install and guide here:
https://www.npmjs.com/package/npm-check-updates
when running 'ncu' on the command-line in your root-folder where your package.json is, it will list the packages that can be updated and by running 'ncu -u' on the command-line it updates all the packages for you.

bootstrap#4.0.0-alpha.3 invalid

Installing bootstrap 4 via npm I keep getting the same error:
Any ideas how to successfully install bootstrap 4 with npm? I have tried all options from this answer
May be you missed to add --save after the npm command
Use this:
npm install bootstrap#4.0.0-alpha.3 --save
For latest version :
npm install bootstrap#next --save
To install bootstrap 4.0.0-alpha.6 using your package.json file, you need to add this to the devDependencies:
"bootstrap": "4.0.0-alpha.6"
Hope that helps.
Workaround: Installed it with bower instead and it worked.
bower install bootstrap#v4.0.0-alpha.3