Reinstall package from package-lock.json file - javascript

Consider this scenario:
I installed some packages like jquery and bootstrap with npm install.
After this npp make a package-lock.json file that describes installed package info.
When I push folder project to git server node_modules folder wasn't sent because of gitignore and only json file is placed on server.
If someone clone this repo he only has json file. How we can restore or reinstall all dependencies from package-lock.json file?
I tried npm install, npm ci, npm i but nothing restored.
Any idea?

Simply you need to run 'npm i' from your project folder. Also make sure, that all your dependencies are in your package.json file. And you need to track changes in your package.json file in future, because commiting 'node_modules' is a real bag thing. it will be always ignored by *.gitignore settings.
Also use "npm i %package% --save" to add current package to package.json.

Related

SPFX- Can not run gulp ser for the first time

I face this issue when I run gulp serve for the first time :
Error: Cannot find module '#rushstack/module-minifier-plugin'
Plz help me, Thanks!
1.Check your node_modules folder first.
When you install npm packages, npm will create a node_modules folder in your project root. It will also add packages you’ve installed to your package.json and package-lock.json files.You can confirm that a package has been installed by making sure it’s listed in your package and package-lock.json files. And double-check your node_modules folder to make sure the package is in a subfolder there.
2.Install the module.
As your gulp is complaining about the package missing,add it to your package.json and run npm install.

create-react-app always throws babel error

Every time I create a create-react-app project it throws this error:
The react-scripts package provided by Create React App requires a dependency:
"babel-loader": "8.0.4"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:
/Users/dalegrant/Desktop/hyberchat-dashboard/client/node_modules/babel-loader (version: 8.0.5)
I have tried downgrading to 8.0.4,
I've tried installing 8.0.5
I've even made sure all my dependencies for babel rely on a 8.0.5!
I have no idea what to do from here as the error persists for every create react app I now build!
This must be a common problem, does anybody have an idea on how to get around this?!
In your machine user folder there is a node_modules directory and package-lock.json remove them using rm -rf User/node_modules and rm -rf User/package-lock.json after that delete node_module directory and pack-lock.json file in your project run npm install again then it's works
Remove the babel-loader package (also globally):
npm uninstall babel-loader
npm uninstall babel-loader -g
Then run create-react-app again, it should install the correct dependency.
If you use the babel-loader somewhere else, pin the dependency there to ensure this problem does not happen again.
you probably installed node_modules in your main folders before. Search for them and remove.
In my case i have installed node_modules on my Home folder. When i removed files from this directory problem disapeared

npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'

I just want to install socket.io to my project which is located on 3.chat folder. But when I run following command it shows following Warnings.And its not created a node_modules directory inside my project folder. How to fix this?
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io
C:\Users\Nuwanst
`-- socket.io#2.0.3
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'
npm WARN Nuwanst No description
npm WARN Nuwanst No repository field.
npm WARN Nuwanst No README data
npm WARN Nuwanst No license field.
If you already have package-lock.json file just delete it and try again.
Have you created a package.json file? Maybe run this command first again.
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm init
It creates a package.json file in your folder.
Then run,
C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io --save
The --save ensures your module is saved as a dependency in your package.json file.
Let me know if this works.
Make sure you are on the right directory where you have package.json
You need to make sure that the package.json file exist in the app directory. Run this command where package.json file exists.
For more explanation, I run npm start in c:\selfPractice, but my package.json is in c:\selfPractice\frontend. When I switch to c:\selfPractice, it works.
NOTE: if you are experiencing this issue in your CI pipeline, it is usually because npm runs npm ci instead of npm install. npm ci requires an accurate package-lock.json.
To fix this, whenever you are modifying packages in package.json (e.g. moving packages from devDependencies to Dependencies like I was doing) you should regenerate package-lock.json in your repository by running these commands locally, and then push the changes upstream:
rm -rf node_modules
npm install
git commit package-lock.json
git push
If your folder already have package.json
Then,
Copy the path of package.json
Open terminal
Write:
cd your_path_to_package.json
Press ENTER
Then Write:
npm install
This worked for me
finally, I got a solution if you are getting:-
**npm WARN tar ENOENT: no such file or directory,.......**
then it is no issue of npm or its version it is os permission issue to resolve this you need to use below command:-
sudo chown -R $USER:$USER *
additional
sudo chmod -R 777 *
then run:-
sudo npm i
If you're trying to npm install on a folder that's being rsync'd from somewhere else, remember to add this to your rsync --exclude
yourpath/node_modules
Otherwise, NPM will try to add node_modules and rsync will remove it immediately, causing many npm WARN enoent ENOENT: no such file or directory, open errors.
Delete package.json and package-lock.json file
Then type npm init
after that type npm install socket.io --save
finally type npm install
It works for me
update version in package.json is working for me
I just experienced this error but on looking for the answer online here on stackoverflow I found the answer in the process so I decided to share it also , If this error occurs on a react project you are working on and when you run npm start make sure to change directory into the directory that has react installed in it and it will start working
if your node_modules got installed in say /home/UserName/ like in my case,
your package-lock.json file will also be there. just delete this file, go back to your app folder and run npm init and then npm install <pkgname> (e.g express) and a new node_modules folder will be created for your.
I had this in a new project on Windows. npm install had created a node_modules folder for me, but it had somehow created the folder without giving me full control over it. I gave myself full control over node_modules and node_modules\.staging and it worked after that.
Seems you have installed express in root directory.Copy path of package.json and delete package json file and node_modules folder.
I had the same problem, I resolved by removing all insignificant lines in packages.json e only left "name", "version", "description", "devDependencies", "dependencies", "resolutions". and the error was gone.
the file path you ran is wrong. So if you are working on windows, go to the correct file location with cd and rerun from there.

Is there a way to generate dependencies into a package.json from a yarn.lock?

I'm having trouble syncing my yarn.lock file with my package.json file. If I install my dependencies with yarn install, everything works fine. However, if I do npm install, I end up with some issues. Similarly, if I delete this yarn.lock file and run yarn install, I get those issues as well.
This tells me that there is some issue in my package.json dependencies versions and I've been trying to figure out what is wrong. Is there a way I can remove what I have listed in my package.json and just generate it from my working yarn.lock file? Thanks.

How do I use GruntFile.coffee and package.json to extract/make/fetch/?? the Lungo.js example files?

I am wanting to try out the Lungo.js examples from here : https://github.com/tapquo/Lungo.js,
however the index.html in the example directory is expecting files in the components and package directories and, while those directories do exist as part of this bundle, they are empty of any files.
I have a GruntFile.coffee and a package.json and I believe that together these are some kind of make file that perhaps should make/pull/create the files that the example needs to run, but I don't know how to make them do that.
I have installed the following:
sudo npm install -g grunt-cli
sudo npm install -g grunt
sudo npm install -g coffee-script
I can now run "coffee GruntFile.coffee" successfully, but it does nothing I can see, certainly it is not creating the missing files.
And the "grunt" command simply says "Fatal error: Unable to find local grunt."
How do I tell this bundle of code that I have to get the other files I require?
And, bonus question, what's going on here?
(I understand javascript, and pulling code from github, but not these other frameworks)
package.json has devDependencies field. They need to be installed before you may use grunt command. First you need execute
npm install
in directory wich contains it.
There is definitely bug in this line of Gruntfile
You should change it to:
pkg: grunt.file.readJSON "package.json"
Then, after local grunt is installed, you may run
grunt
which will execute default task. This is well known practice last time.
You need to install grunt locally, not globally. Only grunt-cli should be installed globally.
So instead of
npm install -g grunt
Navigate to your project root folder and execute
npm install grunt
There's a getting started guide on the Grunt homepage.
The package.json file is a descriptor file for your application. More information on this file can be found in this interactive guide. You normally use grunt together with this file so you can list your grunt plugins as dependencies of your application. I suggest reading a tutorial on grunt to learn how it works.

Categories