VS Code cannot read Node Modules file when doing yarn install (it can read when doing npm install) - node.js

When ever I install my packages using Yarn, VS Code is not able to read the node_module files that are using in index.js or for that matter anywhere. However, when I do npm install, it starts working fine.
How can I fix this?
System: Mac - tried different Macs, same result.

I had a similar issue, and I had to do yarn init to get the package.json file to appear in the folder. Once I did that, adding a yarn add added the node_modules in the folder in vscode.

Related

Vite - How to npm run dev when I have deleted both package-lock and package.jason folders?

Im following along a tutorial on YT on how to code and deploy a react website. I created my project using Vite. Everything was reflecting fine on my browser window until I closed the terminal and now my browser returned "This page can't be reached". So I tried running npm run dev one more time and I get a bunch of errors. Looked online for an answer and ended up deleting both the package-lock.json and package.json folders. Now when I run npm install I only get a rather almost empty package-lock.json folder. Is there a way to undo this? I feel like I messed around too much with the terminal. How can I go back to running npm run dev effectively?
You need to install the packages again,
You need to initialize the package again.
I'd suggest going through the source code in order to find out the name of the packages.
npm init
then all you need to do is
npm i pkg1 pkg2 pkg3

NestJs can't find module platform-express even though it's installed in node_modules

I was following a tutorial on Udemy in order to setup a NestJS app from scratch. Upon execution using npx ts-node-dev src/main.ts I get the error [PackageLoader] No driver (HTTP) has been selected. In order to take advantage of the default driver, please, ensure to install the "#nestjs/platform-express" package ($ npm install #nestjs/platform-express).
I tried uninstalling and reinstalling #nestjs/platform-express but I still get same error.
Finally solved this issue, I had to delete the entire node_modules folder and then run npm install with the same pckage.json file.

'ng' is not recognized as a command

This question has been posted several times, however, I have not been able to find a solution.
I am using a new computer given to me by my company.
node -v = 14.7.3
npm -v = 6.14.13
npm, node, and Angular's location have been added to %PATH%.
Angular has been installed globally.
I have tried to remove package-lock and node_modules and reinstalling using npm.
I have tried to install/uninstall in the projects root, the projects application folder (where node_modules and package-lock is located, and inside the parent of the project as well just to give it a go.
After all of that, I am still receiving the error. I even tried the old turn it off and back on again trick as well.
I am unsure what to try from here. Any assistance would be great!
I am worried that there is some permission I am missing. In order to do anything on my work computer it feels that I need an admin to come and sign in for me or take control and do it for me.
Please let me know any troubleshooting options I have, thank you.
Are you using nvm (or nvm for window)
they are used to manage node versions
if you install Angular globally under nvm node12, it won't be available on other node versions
Check what node modules are installed globally
npm list -g --depth=0
If global Angular isn't available just run the local projects version
revert any changes you made to package.json and package-lock.json
remove node_modules
npm install
npm run ng serve -- --port=4200
note the extra --, as you're passing down params to a sub command
I'd advise against installing Angular globally anyhow. Look up running angular cli with npm run ng or the equivalent via npx

Why is "npm install" looking for a file that doesn't exist (package.json) on a fresh NodeJS installation?

Hello, World!
I am having trouble getting NPM working.
First, I installed node.js from https://nodejs.org/en/download/ (the 64-bit .msi, on Windows 10, Version 10.0.18362 Build 18362). Node -v is 12.16.3.
Using Powershell, I navigated to the nodejs directory created in the install. Then I attempted npm install, which ultimately drew a series of errors beginning with "ENOENT: no such file or directory, open '...\nodejs\package.json' ".
The nodejs directory contains a file called "package-lock.json", but no "package.json".
Renaming the "-lock" file did not fix the error.
I've read on this site that Node came with NPM pre-installed. I can run npm -v without a problem ("6.14.4" returned) but trying npm start gives me the same error as npm install (cannot find package.json).
I have uninstalled Node & reinstalled twice, same problem.
Thoughts?
You should create a package.json file for every project using npm libraries, whether or not you are going to publish your code anywhere.
The easiest way is to run npm init and answer the questions, then npm will create the package.json file.
(Or take a look at the docs for other ways to run init, like npm init -y to just generate a plain package.json that you can manually edit.)
BTW, package-lock.json is a different kind of file that's generated to say which versions of each transitive dependency were installed. It doesn't have the same format as package.json; don't mix them.

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 ;)

Resources