Gitlab CI Failed: NPM command not found - javascript

I have been playing around Gitlabl CI but for some reason I can't get my tests to "passed". It always says npm: command not found
My Gitlab CI config looks like this:
image: node:latest
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
before_script:
- npm install
- npm install eslint -g
- npm install eslint-plugin-react -g
- npm install babel-eslint -g
test:lint:
script:
- eslint src/*
I keep getting the error below and I have No Idea why:
By the way, Im NOT using the gitlab shared runner. Not sure if that contributes to the problem but just to make sure, the machine that has my gitlab runner has all the necessary packages to run nodejs.
Your help is greatly appreciated
Best regards,

The image tag specifies a docker image, hence you must specify the executor of your runner to be docker. Did you perhaps set it to be something else, like shell, when you created the runner?

You can use like below:-
stages:
- build
- deploy
deploy-prod:
image: node:12.13.0-alpine
stage: deploy
script:
- npm i -g firebase-tools

I have same problem.
Gitlab-runner use user of 'gitlab-runner' default when it starts. So the user have not root access.
ps aux|grep gitlab-runner
copy the shell of running
change user:
run /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root in bash.
gitlab-ci runner test
pass!
kill old pid
nohup /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root
ps: gitlab-runner -u root also change user.

Your cli is taking ssh executer by default. You probably need docker. Try adding tag in your yml script.
tags: [ <your docker image name> ]

This helped me:
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

In my case, there are two gitlab-runner. There is no node enviroment in the specific Runner.Then I stopped the wrong one

Related

NODE_ENV' is not recognized as an internal or external command, operable program or batch file

I am learning NODE js and i have a server file that includes NODE_env as port configuration , the code works on a MAC but throws up an error on my windows. How do i solve this?
Have you tried installing it globally or include it in your project's or your library's optional dependencies?
if not, try this:
install globally:
npm install -g win-node-env
Or you may include it in your project's or your library's optional dependencies:
npm install --save-optional win-node-env
refer below link for more information
npmjs win-node-env
If you run into this problem in 2021, install cross-env as a dev dependency by running npm i -D cross-env.
Then, modify your command in the package.json file thus:
cross-env NODE_ENV=development node my_script.js
Are you asking how to set NODE_ENV in windows? You can set it as a user or machine environment variable. You can also set it when you call the script in the command line:
NODE_ENV=development node my_script.js

Cannot install my own npm package

I've been developing a later-to-be-release Open Source project with Node as a CLI tool. The CLI itself works great I only need to test if it works while on another project, so for that I installed the projects globally npm install -g without errors, but for the life of me I can't use the CLI.
I get the following error:
The odd thing is that the directory and file does exist in the global npm folder:
This is the project's package.json:
Am I not understanding how making a npm/node CLI works? What I'm missing?
EDIT 1:
This is my index.js file:
And this is the commander.js file:
EDIT 2:
After creating a test project as #AngYC suggested I could use the test cli successfully, while inspecting the difference I found this. Inside C:\Users\Ivan\AppData\Roaming\npm the .cmd of both projects are quite different:
EDIT 3 (Solution):
After fiddling around I found out that the file that really needed the shebang (#!/usr/bin/env node) was only index.js file and not the commander.js one. Removing the shebang in that file solved the problem
You may want to try to link your local package to your global executable list.
https://docs.npmjs.com/cli/link
All you have to do is run npm link in the folder you got your tool and it should make the command available globally.
Try to uninstall cli run npm rm -g cli or sudo npm rm -g cli. Then you run: npm install cli -g
If the problem persist, you might want to remove you npm package globally, probably there might be some conflicting things running.
Type this: %appdata% (either in explorer, run prompt, or start menu).
You can simply remove all globally installed npm packages by deleting the contents of:
C:\Users\username\AppData\Roaming\npm
Then you might also want to clear all the your cache run npm cache clear or npm cache clear --force as the case might be.
Then you reinstall all your packages that were install globally again.
If problem still persist, check this:
When you run npm root -g, it yields C:\Users\<username>\AppData\Roaming\npm\node_modules, or even, you should check your path maybe the executable binaries and .cmd files end up in C:\Users\<username>\AppData\Roaming\npm instead of C:\Users\<username>\AppData\Roaming\npm\node_modules, you will need to add that path to the PATH env. variable.
I hope this resolves your issue.

electron js with python 3.6, print error on npm start, downgrade python?

this is my first electron js installation, and I had to download and install its electron, NPM install (in the folder electron), but when at the start, failed.
error on print, or if I had to do python downgrade?
My error screenshot:
Make sure that you are writing python3 style code. Like when you write print It should be print(...)
I had a similar problem when installing on windows. Possible solutions:
First check the versions od npm and node, update it with this commands:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash
Install again node:
sudo apt-get install nodejs
And update:
npm update -g
If it doesn't work try to update or reinstall Phyton an put it in global environment variables path.
Check the electron git and try to download the last version manually.
Other solutions:
Install or reinstall Windows .Net.
Install or reinstall Visual Basic c++
Update the package dependencies of the node

Node js npm installed global package cannot be called from terminal, tried everything

I have installed some node js packages globally on my MAC.
I run $sudo npm install -g jshint in my terminal at my root directory which is /Users/apple/.
And I try to run $jshint myfile.js, but only got this error:
-bash: jshint: command not found
I have tried everything :
added NODE_PATH="/Users/apple/npm-global/lib/node_modules"
Changed $sudo chown apple /Users/apple/npm-global/
Changed $sudo chown apple /Users/apple
Changed $sudo chown apple /Users/apple/Tutorial/Nodejs/myfile.js
Any ideas? Thanks in advance!
EDIT
--------------------------------------
So I have reinstalled node js using brew, and I followed all the default folders which is usr/local/ , but still, $npm -g ls shows /usr/local/lib and my jshint package is successfully installed in /usr/local/lib, run $jshint, "-bash: jshint: command not found"...
run the following to see where global libraries are installed
npm list -g
Try not to use sudo with npm. If you can, uninstall npm and install it again with a simple brew install without sudo. Nevertheless, if you do not want to use Homebrew, npm has a guide for fixing issues like this.
npm config get prefix
will give you the npm's directory. If it's not /usr/local (the default on macOS), change it:
npm config set prefix /usr/local
Ultimately, if nothing works for you, you could try to chown npm's folder to your user.
Edit: If you want to keep the path /Users/apple/npm-global as your default npm path, you're going to have to add it to your $PATH global variable.
vi ~/.bash_profile
Append this command: export PATH=$PATH:/Users/apple/npm-global and then make sure to save the file.
Run this to apply the changes immediately: source ~/.bash_profile
Finally, verify that your path has been succesfully added: echo $PATH

nodemon command is not recognized in terminal for node js server

I am doing node.js server setup from https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens. I am new in node.js. I am installing npm install nodemon --save. But when I am run the server with this nodemon server.js.
In the terminal showing:
nodemon is not recognized as internal or external command, operable
program or batch file
node server.js command is working and started the server, But nodemon command is not working.
I am set up the node js server from https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens video.
I don't know why it is not working I have tried some command for the install nodemon.
npm install -g nodemon
npm install -g nodemon --save
npm install --save-dev nodemon
npm install -g nodemon#debug
npm install -g --force nodemon
I have seen one link I can´t install nodemon globally, "nodemon" not recognized, But I don't know how to set the path because of my project location in D drive.
I want to run nodemon server.js. How can this be done?
You need to install it globally
npm install -g nodemon
# or if using yarn
yarn global add nodemon
And then it will be available on the path (I see now that you have tried this and it didn't work, your path may be messed up)
If you want to use the locally installed version, rather than installing globally then you can create a script in your package.json
"scripts": {
"serve": "nodemon server.js"
},
and then use
npm run serve
optionally if using yarn
# without adding serve in package.json
yarn run nodemon server.js
# with serve script in package.json
yarn run serve
npm will then look in your local node_modules folder before looking for the command in your global modules
Install nodemon globally:
C:\>npm install -g nodemon
Get prefix:
C:\>npm config get prefix
You will get output like following in your console:
C:\Users\Family\.node_modules_global
Copy it.
Set Path.
Go to Advance System Settings → Environment Variable → Click New (Under User Variables) → Pop up form will be displayed → Pass the following values:
variable name = path,
variable value = Copy output from your console
Now Run Nodemon:
C:\>nodemon .
No need to install nodemon globally. Just run this npx nodemon <scriptname.js>. That's it.
First, write npm install --save nodemon
then in package.json write the followings
"scripts": {
"server": "nodemon server.js"
},
then write
npm run server
I was facing the same issue. I had installed nodemon as a dev-dependency and when I tried to start the server it gave the message that
nodemon is not recognized as internal or external command, operable
program or batch file
Then I installed it globally and tried to start the server and it worked!
npm install -g nodemon
To use nodemon you must install it globally.
For Windows
npm i -g nodemon
For Mac
sudo npm i -g nodemon
If you don't want to install it globally you can install it locally in your project folder by running command npm i nodemon . It will give error something like this if run locally:
nodemon : The term 'nodemon' 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.
To remove this error open package.json file and add
"scripts": {
"server": "nodemon server.js"
},
and after that just run command
npm run server
and your nodemon will start working properly.
This may come to late, But better to say somthing :)
If you don't want to install nodemon globbaly you can use npx, it installs the package at run-time and will behave as global package (keep in mind that it's just available at the moment and does not exist globally!).
So all you need is npx nodemon server.js.
npx can be used out of the box from npm#5.2.0 version and up.
I had the same error a few minutes ago and this is how I've solved it:
1. Install "nodemon" Globally
npm install nodemon -g
2. Then you need to add the npm path to the environment variables
To find the path do this in the terminal:
npm config get prefix
You'll get the output that looks like this: C:\Users\user\AppData\Roaming\npm
If you're not sure about how you can update environment variables on Windows, check this out: Here
3. Run the app again with "nodemon"
Before you run the app, create a new terminal to make sure that the terminal recognises the changes in the environment variables.
Then run:
ex:
nodemon server.js
Does it need to be installed globally? Do you need to be able to just run nodemon server.js ? If not, you could always just call it from your local project directory. Should be here:
node_modules/.bin/nodemon
This line solved my problem in CMD:
npm install --save-dev nodemon
I tried installing the nodemon globally but that doesn't worked for me.
whenever i try to run it always shows me the error:
nodemon : The term 'nodemon' 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.
2. I have found two solutions for this
solution 1:
What i have tried is to update the "scripts" in package.json file and there i have added
"server": "nodemon app.js"
above line of code and after that
npm run server
Soluton 2:
Press the Windows key.
Type "Path" in the search box and select "Edit the system environment variables"
Click on "Environment Variables" near the bottom.
In the "System Variables" section double click on the "Path" variable.
Click "New" on the right-hand side.
Copy and paste this into the box (replace [Username]):
C:\Users[Username]\AppData\Roaming\npm
restart your terminal and VSCode.
Then type nodemon app.js to run the nodemon
i applied solution 2 as we just need to run nodemon [filename.js]
I have fixed in this way
uninstall existing local nodemon
npm uninstall nodemon
install it again globally.
npm i -g nodemon
It is better to install nodemon globally instead as dev dependency to the project.
npm install -g nodemon
Official NPM CDN: Link
This package is used to monitor changes in the javascript files and re run the npm start so that it is easy to dev purposes.
Since node prefix is not in the PATH ENV variable , any of the globally installed modules are not getting recognized.
Please try this.
Open cmd prompt
npm config get prefix
append the resulting path to PATH env variable.
Now you should be able to run nodemon from any location.
try this link and follow it.fixing npm permissions
https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-default-directory-to-another-directory
You can run your node app by simply typing nodemon
It First run index.js
You can put your entry point in that file easily.
If you have not installed nodemon then you first you have to install it by
npm install -g nodemon
If you got any permission error then use
sudo npm install -g nodemon
You can check nodemon exists or not by
nodemon -v
For me setting the path variables was enough for the solution:
Step 1) Install nodemon globally using npm install -g nodemon
Step 2) Set the ENVIRONMENT VARIABLES, by adding npm path the PATH variable
1) Open Control Panel, search for environment variable
2) Click open the environment variable
3) Create new variable NPM set it with the path of npm as appears from the nodemon installation cmd output (as seen from nodemon installation screenshot):
4) Now add NPM variable to the PATH variables:
Step 3) Close the 'cmd' and open a fresh one and type nodemon --version
Now we have the nodemon ready to use :)
This issue is also possible if running scripts is disabled on the system. In order to enable it:
Open Windows PowerShell with Run as Administrator
Execute:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
npm install -g nodemon
nodemon app
Just had the same problem after creating a new user profile on my development machine.
The problem was that I wasn't running the console (command prompt\powershell ISE) as admin.
Running as admin solved this problem for me.
Just install Globally
npm install -g nodemon
It worked for me on Windows 10.
nodemon app.js
The Set-ExecutionPolicy cmdlet's default execution policy is Restricted for Windows.
You can try installing nodemon by setting this policy to Unrestricted.
execute command : Set-ExecutionPolicy Unrestricted
and then try installing nodemon and execute command: nodemon -v
First you need to install nodemon globally by using this command:
"npm i -g nodemon" (for Windows) and "sudo npm i -g nodemon" (for Mac)
then run
"nodemon app.js"
Now you will be fine.
Run this command:
npm install nodemon -g
Now it will install the nodemon but the problem with my case is that it is installing nodemon somewhere else.I added Nodejs path from (ProgramFiles(x86)) but that did not worked so i found another solution.
Run above command
There will be a path shown during installation where nodemon is installed,then
[Kindly go to below link to see the path][1]
[1]: https://i.stack.imgur.com/ld2sU.png
Copy the path upto npm and set it to environment variable
Now try the below command,hopefully it will run
nodemon YourAppName.js
All above options are failed, I got the permanent solution for this.
Add below line in package.json under dependencies and run npm install. This will add nodemon package to node_modules and there you go, enjoy the coding.
"nodemon": "^1.17.*"
Try in your packge.json:
put "./node_modules/.bin/nodemon" instead of just "nodemon".
For me it works.
This help me with the same problem to start both nodemon and graphql servers
npm run dev
Step 1: $ npm install nodemon --> install nodemon on your project
Step 2: Add serve in script on package.json file as:
"scripts": {
"serve": "nodemon app.js" // you can change file name accordingly
}
Step 3: $ npm run serve
The following worked for me on windows 11.
Type npm install in the terminal. (Within the same directory as the project)
Then type npm run serve to run the application from the default browser.
Remove nodemon because it's a dev dependency and use node instead of it.
"scripts": {
"start": "node server.js"
},
This worked for me.

Categories