HelmetJS on Yarn Package not installing - node.js

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.

Related

react-scripts is not recognize

I have problem about react project when I hit enter the command like yarn start so I have face the mentioned problem like react-script is not recognize internal or external command. I have this script in dependencies but still I face this problem.
I have the latest version of node, and I have updated npm but still I have this problem.
Try this command: npm add react-scripts --include=dev
Make sure that you are inside the project folder before you use the yarn start command.
Or try deleting the cache and node-modules and package-lock.json and re-install it.
You can try manually installing react-scripts for your application.
1 . Try yarn install
2 . If the problem is not solved yarn add react-scripts --dev

Run `yarn remove <dependency_name>` to remove dependency, but yarn.lock still shows the removed dependency

In my node.js project, I had using yarn installed the dependency #nestjs/jwt, now I want to uninstall it since I am not using it.
I run yarn remove #nestjs/jwt. It was successful. I checked my package.json, it was removed. But when I check the yarn.lock file, it is still showing. Why is that?
My git add -p yarn.lock shows me:
-"#nestjs/jwt#8.0.0", "#nestjs/jwt#^8.0.0":
+"#nestjs/jwt#^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/#nestjs/jwt/-/jwt-8.0.0.tgz#6c811c17634252dd1qcd5dabf409db4692b812da"
integrity sha512-fz2LQgYY2zmuD8S+8UE215anwKyXlnB/1FwJMLVR47clNfMeFMK8WCxmn6xd0hF5JKuV1crO6FVabb1qWzDxqQ==
Besides packages you explicitly install, packages depend on other packages. To see a graph of any dependents of this package you have installed, do:
yarn why #nestjs/jwt -R
Yarn.lock is what yarn uses to know what versions of each dependency are installed so it can get those exact versions again when you run yarn install on a new machine. Try running 'yarn upgrade'. This should create a new yarn.lock file without those dependencies.

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

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.

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 to sync `yarn.lock` with `package.json`?

I installed a package with yarn add --dev, run its setup process and during it, the package installed several other packages and added those to package.json (in devDependencies), I assume with npm. Great, but now my yarn.lock is out of sync.
What is the correct, non-manual way of syncing yarn.lock to the current state of package.json?
Edit: yarn check shows the missing packages as:
error Lockfile does not contain pattern: <package>#<version>
But it doesn't add them.
Run yarn install, or just yarn.
The lock file is updated in its entirety on any change to dependencies, i.e. when you run a yarn command.
From the Yarn docs:
Your yarn.lock file is auto-generated and should be handled entirely by Yarn. As you add/upgrade/remove dependencies with the Yarn CLI, it will automatically update your yarn.lock file. Do not edit this file directly as it is easy to break something.
(Emphasis my own)
If you ever face a checksum issue this will solve it,
YARN_CHECKSUM_BEHAVIOR=update yarn

Resources