how to fix yarn.lock and package-lock json mix - node.js

So i was going on with my nodejs project and was trying to install a package with npm, but it got stuck in the process. I found I could use yarn which i, the very next second, did. It worked, but now im trying to host it on Heroku and I have both, package-lock.json and yarn.lock. If i delete any, the dependencies get outdated. how can i fix this?
My dependencies:
express,
passport,mongoose,ejs
I tried and searched the web for a while but nothing seemed to help me.

Just do yarn install and it will install all the dependencies again with updateing the yarn.lock. And then you can delete package-lock.json.

Related

Module not found: Can't resolve '#react-stately/collections' in Next.js app

I was working on the Next.js app. I installed the react-use package in my Next.js project!
Suddenly Next.js started throwing errors!
Then, I searched for similar errors on Stackoverflow. Some of them suggested removing node_modules and package-lock.json and trying to reinstall npm packages. I did so, but nothing seems working! Then restarted VSCode and computer, but the error was still there!
Even I tried to install that package, which is shown in error, but again it throwing an error for another package.
I am not sure why suddenly started throwing errors!
This is my package.json
I tried to update NextUI's latest version which is "#nextui-org/react": "^1.0.0-beta.9"
My current package.json file, after updating the NextUI
Try to clean the cache and delete node_modules then install it again
npm cache verify
npm cache clean --force
Delete node_modules
npm install

HelmetJS on Yarn Package not installing

I am building a micro-service and using Yarn Package to install helmet/helmetjs. But I am receiving this error which is shown on the image below. What could be the problem?
I just removed the yarn.lock and node_modules, and run the command yarn install.
The possibility of this issue is due to corrupt node_module and yarn.lock.

Facing an issue after cloning React repo

HI there I'm facing an issue after cloning a react repo(attached)-
PS C:\Users\User\Desktop\gfolio> npm start
gfolio#1.0.0 start
react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack-dev-server": "3.11.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack-dev-server was detected higher up in the tree:
C:\Users\User\node_modules\webpack-dev-server (version: 3.11.1)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
Delete node_modules in your project folder.
Remove "webpack-dev-server" from dependencies and/or devDependencies in the package.json file in your project folder.
Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions.
Check if C:\Users\User\node_modules\webpack-dev-server is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Try running npm ls webpack-dev-server in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack-dev-server.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
I tried to fix it through the above method but not working,

Why do Node modules go into .staging folder?

I have an Electron app that I'm trying to install node modules for. When I run npm install, it creates the node_modules folder but all the modules go into a subfolder called .staging. Each module also has -xxxxx appended to it, where the x's are some random alphanumerics.
Other Electron apps I've created have never done this. All the node modules sit in the root of node_modules and don't have -xxxxx appended.
Any idea why this is happening?
I was also facing the same issue, I tried the steps below:
Delete package-lock.json
Delete Node Modules folder
Try installing it using below command (should be in open network)
npm install
Note: - ".staging" means, those dependencies are getting downloaded so for the temporary basis it keeps all those dependencies under ".staging" folder. Once all gets downloaded properly then it will showcase them under node_modules only.
I hope this will work.
This only happens temporarily until the modules are downloaded and installed. Node seems to do this so it can place together common submodules from all the modules you are installing so it can better structure the node modules folder(mainly for windows users).
If this is happening after an npm install finishes it is likely that there is something wrong with your node installation or something in the install failed.
If you're automatically installing node_modules using CI/CD you should check out npm ci. Also check out this Stackoverflow question.
npm ci
The documentation points out the differences between npm install and npm ci.
The project must have an existing package-lock.json or npm-shrinkwrap.json
If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
If a node_modules is already present, it will be automatically removed before npm ci begins its install. This is nice, because it prevents having to do something like rm -rf node_modules.
It will never write to package.json or any of the package-locks: installs are essentially frozen.
.staging is a temporary npm folder, where the modules are temporarily saved while they are being downloaded, if the package.json downloads are still not completed, the created folder remains, until the installation is complete.
The problem may be lack of space on your hard drive.
I was having 2 versions of node installed on my system.
nodejs v4.2 and node v8.6
I thought this could be conflicting, so I deleted nodejs v4.2 with following commands.
sudo apt-get remove nodejs
and linked the path with
sudo ln -s /usr/bin/node /usr/bin/nodejs
Again I ran npm install and it got fixed
Delete package.lock.json
Delete node_modules
run npm update
This worked for me
I moved the project from C drive to other drive and ran the following commands
take a backup of older node modules if you are running this and existing project
npm cache clean --force
npm update
I faced similar issue and tried the above answers but it did'nt worked for me;
I followed below steps to resolve this issue-
1.npm audit
By running npm audit I got list of pending packages to install-
2.npm i packagename
After installing one or two package one by one from list, I used
3.npm install
At this time the installation went smooth without any lag or hangup. Hope this help who is facing similar issue :).
Sometimes the cache is corrupt and also unremovable.
This fixed the issue I was experiencing.
If you are using nvm
Get the current node version node --version
nvm uninstall (that version)
nvm install (that version)
nvm use
npm install
If you have a windows machine where you do not posses Admin rights to it.
Try deleting node_modules and install using 'npm install' from command line as
'ADMINISTRATOR'
It works!
Anyways, it comes down to an open network thing ;)

How do I install Bower packages with Yarn?

From the project's README:
Multiple Registries: Install any package from either npm or Bower and keep your package workflow the same.
I'm assuming that means that I can install my Bower packages (listed in my project's bower.json) with Yarn. If this is the case, how would I go about doing that?
I'm not seeing any mention of Bower or using separate registries in the documentation. However, I do see the Bower registry listed in the source.
UPDATE 11/4/16: Yarn decided to remove support for Bower. See the Github pull request and Bower's blog. =(
ORIGINAL:
Bower just posted a blog post about this topic. They seem excited about it, but point out that there are currently unresolved issues:
Important note: As it stands right now there still seem to be some issues regarding Bower support. We are however confident that with the help of the community, these issues will be solved quickly as Yarn steps towards 1.0 in upcoming months.
He also refers to a pull request for a bower patch.
When I ran yarn, it deleted my bower_components folder (GitHub ticket here)! I really like yarn though, can't wait for the bower bugs to get resolved.
If you add the following to package.json, bower install will be called and it works. It is a workaround though:
"scripts": {
"postinstall": "bower install"
}
Apparently, it should just work. Unfortunately, there's currently a bug where, if you have both a package.json and bower.json in the same project, only the npm packages are installed and the bower packages are ignored.
Normally, one would simply yarn or yarn install and both npm and bower dependencies would be installed.

Resources