Visual Studio Code - NPM not found when using NPM SCRIPTS - npm

If I open the integrated terminal and run npm -v it works.
But, if I running it directly from NPM SCRIPTS it doesn't work.
MORE DETAIL AS REQUESTED IN COMMENT
// Edit by Fogmeister
I also have this problem, here is some more detail...
I have a test script defined in package.json...
When I run this script from the root folder command line using npm run test it works...
This script appears in the list of NPM Scripts in VS Code...
When I run from the NPM Scripts explorer it fails...
Even though it says it is running from the same folder.

Try doing, use dnf or apt-get
sudo apt-get/dnf install npm
The npm file should be in /usr/local/bin/npm. If it's not there, install node.js again with the package on their website.

Related

Cypress cannot run because this binary file does not have executable permissions

I was trying to create a new project in cypress and I got the following strange error message.
Steps:
npm init -y
npm install cypress --save-dev
I then did npx open cypress and I got the following message from my console
How do I fix this?
Cypress cannot run because this binary file does not have executable permissions here:
/Users/myName/Library/Caches/Cypress/7.5.0/Cypress.app/Contents/MacOS/Cypress
Reasons this may happen:
- node was installed as 'root' or with 'sudo'
- the cypress npm package as 'root' or with 'sudo'
Please check that you have the appropriate user permissions.
You can also try clearing the cache with 'cypress cache clear' and reinstalling.
----------
Platform: darwin (20.5.0)
Cypress Version: 7.5.0
You can do two things:
Run the command npm cypress cache clear and then again install cypress npm install cypress --save-dev and check.
Or, install npm globally without sudo using the command npm install -g. Then create a new folder and then run npm init, npm install cypress --save-dev and npx cypress open.
Do navigate to the cache directory by doing
cd /Users/myName/Library/Caches/
Here you have to delete Cypress directory completely by running the command
rm -rf Cypress
Now head over to your project directory and run the command
npx install cypress
Cypress will be installed in your system again. Next time you won't get any errors.
So, I had a chat with the dev team at Cypress and got the following answer. After reading the logs I had a feeling this might be the root cause. So please check you have the most up to date version of Node.js

On Mac M1, can't run scripts in package.json: - sh: <dependency>: command not found

I just got a Mac Mini M1 for personal use, and I'm trying to run a preexisting React app. I installed nodejs and npm successfully, and running npm install does add the node_modules folder correctly as far as I can tell; but whenever I run npm start or npm run <script>, I get an error. It seems that npm can't access any of the project's dependencies. I've tried this using the rosetta terminal as well with the same results.
For an example, I initialized a new React project with npx create-react-app test_app, then cded into it and ran npm start. I got:
test_repo#0.1.0 start
> react-scripts start
sh: react-scripts: command not found
How do I get these commands to run properly and launch the app?
Here's what I'm using for node and npm:
➜ test_repo npm -v
7.6.0
➜ test_repo node -v
v15.11.0
I found a (very) hacky solution for now. I'm no expert with npm, but what I discovered is that npm scripts refer to dependencies indirectly - for example, having a command that says
"test": "jest"
tells npm to look in node_modules/.bin for a file called jest and to run that.
the issue is something to do with npm understanding this. But it's possible to get around that by putting the address of each dependency in the script, for example:
"test" "node_modules/.bin/jest"
I was able to get things to build this way. If someone comes along with a better answer, please show me up :P

Azure DevOps - npm invisible

I have a strange problem with a release pipeline in Azure DevOps.
I have two tasks:
1) Install packages
2) Run npm using the above packages
All seems to be easy so what I do is:
1) Command line task
npm install -g mkdirp 1.0.3
npm install -g newman
npm install -g newman-reporter-junitfull
2) PowerShell task
$(newman run $collection -e $environment --env-var "x=$(x)" -r junit --reporter-junit-export $resultFile)
This all worked fine until today. I tried a lot, but nothing works.
The error I have is:
newman : The term 'newman' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and
try again.
Did anyone have a similar issue?
I ran above npm install scripts in a Command line task, and found only the first npm install command got executed. And my following powershell task to run newman command failed with above error message too. You can check the log of Command line task to see if it is the same issue.
If you want to report this issue, you can report a problem here.
The workaround i found is to run the npm install commands in a Powershell task too, do not use Command line task. Then the npm install commands will all get executed and the following powershell task can run successfully.
Or you can separate above three npm install commands into three Command line tasks to install them separately, which will make sure the newman library is installed.

How to solve 'vue-cli-service' is not recognized as an internal or external command?

I am getting an error when trying to run npm run serve. At first I installed node.js then vue as well as vue/cli.
But when I am trying to run server as -> npm run serve at that time I'm getting error like 'vue-cli-service' is not recognized as an internal or external command.
I used below codes for installation:
npm install -g vue
npm install -g #vue/cli
can someone guide me what to do to solve this issue ?
I think you are using cmd in windows.
Try deleting the node_modules folder and after that run npm i from the cmd.
Then try running npm run serve again and see if it works this time
Install vue/cli-service globally
npm install #vue/cli-service -g
This will install global npm package.
#vue/cli-service is usully installed as global, because you do not usually copy these types of packages to every project.
If the global npm package gets corrupted, it is not stored in node_modules folder, but rather in other depending on the os. Therefore removing node_modules does not help. Locations for global node_modules folders are
%USERPROFILE%\AppData\Roaming\npm\node_modules (Win10) or
/usr/local/lib/node_modules (Linux),
check this stack overflow post on how to locate global packages.
it will depend on the package manager you are using
delete node_modules
if you are using yarn run yarn or yarn install and then yarn serve
if you are using npm run npm install and then npm run serve
In my case, the package #vue/cli-service is installed in my local node_modules environment, but not my global environment, so it cannot be used as a command. I type .\node_modules\.bin\vue-cli-service serve and it works.
As it is mentioned in terminal that node_modules is missing from your project, so you can't directly use npm run serve, first you have to do npm install then do npm run serve. It will work fine
In my case I ran below commands in GitBash and it worked fine
npm install
npm run serve
If you are using cmd in windows.
deleting the node_modules folder and after that run npm istall from
the cmd.
run npm run serve and see if it works this time
In my case, I have checked the folder of node_modules was missing. I am using Windows. So I run this in cmd.
npm install
npm run serve
Then I check it in localhost like usual.
This issue mostly happens when either #vue/cli is not installed or in most cases,
#vue/cli is already installed and you are currently working on a project and when running
yarn serve or npm run serve.
Most at times, this issue is been caused by broken dependencies.
to fix this issue, simple run
yarn install or npm install
depending on your package manager.
well after trying all the solutions above and it still haven't worked for you then you probably have a stupid space in the full directory of your Vue project like in my case. so remove that that space and it will work from then on.
Remember to set the NODE_ENV=development and run npm install again
Try changing the project path to one without spaces, it worked on windows 10
I had faced the same problem in windows. Then
first I deleted the node_module. then I run npm install.
For Windows you should modify package.json to:
"scripts": {
"serve": "vue-cli-service.cmd serve",
"build": "vue-cli-service.cmd build",
"lint": "vue-cli-service.cmd lint"
}
,
I had the same issue using windows + WSL2 (Ubuntu 20.04). Looking at the logs generated after trying to run npm i I noticed that my WSL2 environment did not have python2 installed. So to solve I ran the following commands:
sudo apt-get install python2
rm -rf node_modules
npm i
npm run serve
I faced the same in Windows. Had to run npm install again. Then it worked perfectly.
Wait, what's the difference between #vue/cli and #vue/cli-service? When you install both, they show different number of packages installed. The latter solved my issue actually but everyone keeps saying install #vue/cli.
try running npm i or npm install and then proceed to run npm i vue after previous installation done. works for me
you need use "npm install" at Command Line
Before running "npm install", try running this command first:
npm set strict-ssl false
Like you, I got the error below when I ran npm run serve from the CMD command line,
'vue-cli-service' is not recognized as an internal or external
command, operable program or batch file.
I got past this familiar error by using the following command to add the npm folder to the PATH that CMD searches for executables:
path=%path%;C:\Users\<USERNAME>\AppData\Roaming\npm
where <USERNAME> is your Windows user profile directory name. Only then was I able to run the following commands successfully:
npm install
npm run serve
What solved the issue for me was renaming the directory. I had used the symbol "&" on the folder name and it seems to break things, so changing it to "and" fixed the issue.
This will probably be an incredibly niche thing, but if I help even 1 person it's fine by me.
I have a project, I can run it well on Linux, but i have the same issue on windows, I solve it this way (I hope in your case it works too):
Delete the node_modules
Install it again with npm i

I get an error during Gulp installation

I'm trying to setup Gulp on my system. As I type in the command "npm install gulp" in the command prompt, I'm shown an error . Please help me install Gulp. I access the command prompt from my office which has limited internet access.
It says npm cannot connect to its registry, try to use npm install with another key. It shouldn't work too.
npm config set registry http://registry.npmjs.org/
Try to run this on command.