gulp command not found - npm

Windows 10 pro x64
I ran the following commands
npm install --global gulp-cli
npm init
Then I changed directory to my project:
npm install --save-dev gulp
then tried to run gulp and got
-bash: gulp: command not found
my package.json file reads
{
"name": "riad-kilani_v4-child",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"dependencies": {
"gulp-cli": "^1.2.2"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-sass": "^2.3.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Any ideas on whats going on here?

I solved the problem creating an alias in ~/.bashrc like this:
alias gulp="node /home/deploy/app/node_modules/gulp/bin/gulp.js"
Just put the alias in the end of the .bashrc file, then run:
source ~/.bashrc
Test with:
gulp -v
You should see something like this:
[15:46:39] CLI version 3.9.1
[15:46:39] Local version 3.9.1

On MacOS Catalina v10.15.2, the following global install with sudo worked for me.
sudo npm install gulp -g

So I ran into this issue as well and none of the top answers were helping. Everything was installed, uninstalled, restarted, installed globally, etc., etc.... and still got the gulp command not found error. So I opened the package.json file and put in the following after the name field:
"scripts": {
"start": "gulp"
},
And then I ran npm start in git bash.
Everything ran correctly, I got my dev view in my browser # localhost and all was right with the world.
Hope this helps!

I had got into the same issue. Even after npm install gulp -g and npm install bower -g, both gulp and bower showed the error.
Here is the thing to remember.
1. gulp and bower command does not run in root (sudo). Switch back to the system user and the run it
2. Make sure the folder where you are running gulp has the user permission. else the permission will be denied
Hope this works for you

I'm using Ubuntu and found the error of -bash: gulp: command not found, too. But it became work after npm install gulp -g

I managed to fix this problem using simple 3 commands found from https://gulpjs.com/
npm install gulp-cli -g
npm install gulp -D
npx -p touch nodetouch gulpfile.js
Hope it helps someone else.
ps: it is not mandatory to use the 3rd command in order to fix the problem.

You can try:
To run this command in the terminal: npx gulp
If want know more visit this Link

For anyone else who runs into this just run npm install and npm update.
I ran npm rm --global gulp to clear out any version conflicts and then ran npm install --global gulp-cli. This did a clean install of gulp and it works flawlessly now.

On MacOS Sierra v10.12.6, the following global install with sudo worked for me.
sudo npm install gulp -g

You didn't mention which versions of node/npm you are using.
We had a similar problem and seems that gulp-sass had to be upgraded.
You can try:
rm -fr node_modules package-lock.json && npm install -g gulp-sass#3.0.0 && npm install

Related

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

How to update local module?

package.json
// ...
"dependencies": {
"my-local": "file:../local/my-local",
// other dependencies
},
// ...
I tried npm install, doesn't work. npm update my-local also doesn't seem to work, possibly because I don't iterate version for each small change I make? (early development stage)
Only reliable way I've found is to npm uninstall my-local and reinstall but it's very annoying.
Is there a better way?
You need another tool for that: https://www.npmjs.com/package/npm-check-updates. Install that with:
npm install -g npm-check-updates
Then:
ncu -u
npm install
the install is necessary as ncu just updates the package.json, not install anything.

'electron-packager' is not recognized as an internal or external command

I recently started using electron. I have successfully completed the 1st phase by creating a hello world app (included files index.html, main.js, package.json). Now I am trying to package the app using electron-packager but getting this error
Steps I have followed:
Created a project directory named helloworld.
Initialized the project directory using npm init command.
Then installed electron using npm install electron --save-dev.
Then created the javascript and html files as main.js and index.html respectively.
Then used npm start to execute the application.
Then installed electron-packager using npm install electron-packager.
Now the problem is coming in this step when i am trying to pacakge the app using command electron-packager .
Perform a global package install:
npm install -g electron-packager
The -g flag tells NPM to install the package globally which makes the command electron-packager available in your PATH.
If you don't want to do a global install you can install it locally and run with npx.
npm install -D electron-packager
npx electron-packager .
Alternatively, you can reference it straight from the node_modules folder (not recommended).
./node_modules/electron-packager/cli.js
There are two cases to make it work...
As discussed above, install electron globally using -g,
i.e. using npm install -g electron-packager
Change in your package.json:
"scripts": {
"start": "electron-packager ."
},
Then type in the command npm start.
This way it worked for me..
If you have installed it locally with:
npm install electron-packager
Then, it's not gonna work, install it globally as a cli:
npm install -g electron-packager
You can also get it through:
"node_modules/electron-packager/cli.js" . --all --asar
After All, if you don't get it working, install electron-packager.
Then, go to your package.json. And beneath your start scripts. Make another string named "build" and give it a value of the electron-packager command you want to run:
...
"scripts": {
"start": "electron .",
"build": "electron-packager . --asar --all"
},
...
Then, go in command prompt or terminal or bash.
Then, type:
npm run build
I might be totally off with it but my fix was that I put the dot without space just make sure in you package.json file its "start": "electron ."
Fixed it for me at least
You've to install electron-packager globally, that's why it shows 'electron-packager' is not recognized as an internal or external command
For this, you have to install electron-package globally
You can install globally by using -g option.
Example:-
npm install -g electron-packager OR npm i -g electron-packager //i stands for install
In my case it doesn't worked after npm global installation.
On the electron-builder Readme page it's recommended to install with yarn.
Yarn is strongly recommended instead of npm.
yarn add electron-builder --dev
Also we can put folder directly to PATH. On Windows 10:
Search with word "environment" and open Edit the environment variables.
Select, edit and Add new value C:\Users\USER_NAME\AppData\Roaming\npm to variable Path. Replace USER_NAME with your Windows username.
Then we might need to restart or logout.
Also in my case I enabled script execution on Windows 10 with instruction on answer below:
PowerShell says "execution of scripts is disabled on this system."

You gave us a visitor for the node type "ForAwaitStatement" but it's not a valid type

I'm getting the following error from a few different libraries in my project, after adding the "stage-2" preset to my .babelrc. (Thats my assumption atm)
e.g. from the DatePicker class in React Native:
node_modules/react-native/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js: You gave us a visitor for the node type "ForAwaitStatement" but it's not a valid type
How can I resolve this error?
I'm using React Native 0.31 and
"devDependencies": {
"babel-preset-react-native-stage-0": "^1.0.1",
"babel-preset-stage-2": "^6.17.0"
},
I too ran into this. Solved by updating my babel-core version by changing the entry in package.json to the latest (at the time of this writing)
// package.json
...
"babel-core": "6.17.0",
...
then running
rm -r node_modules/babel* && npm i
I had the same issue after updating babel-core and some babel plugins. In my case it was fixed by updating babel-cli (globally installed with npm), which was a few versions behind and not using the right babel-core version.
I encountered this after an npm update, struggled for several hours to find a fix, but ultimately solved it via rm -rf node_modules && npm install. I hate npm.
I found this issue is caused by a lower version babel-types, so the solution is just:
npm install babel-types
or a clean npm install:
git clean -fdx
npm install
If your babel-cli is out of date, you might get the same error. Try updateing babel-cli using npm install babel-cli -g or update your local babel-cli and reference it in your package.json scripts.
Also do npm i -D babel-plugin-transform-runtime and add "plugins": ["transform-runtime"] to your .babelrc
Had a similar situation as #Thomas; a globally installed version of babel-cli which was behind. I can recommend not installing it globally, instead running babel through npm scripts.
Local install:
npm install babel-cli --save-dev
In your npm scripts:
"babel": "babel script.js"

Packager won't start

I guess I upgraded node at some point and now when I try to run the packager with npm start it's complaining with:
$ npm start
react-native start
Looks like you installed react-native globally, maybe you meant react-native-cli?
To fix the issue, run:
npm uninstall -g react-native
npm install -g react-native-cli
Node 5.1.0, npm 3.3.12 and react-native 0.15.0
It looks like the preferred way to start the packager now for an IOS app is by hitting the run button in xcode itself or using the following command:
react-native start
I'm using:
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
}
I got the same error.
It turns out it's because npm finds another react-native inside node_modules due to being started with a vastly different environment.
So I changed my package.json to look like this:
"scripts": {
"start": "$NVM_BIN/react-native start"
}
Did you follow the instructions and do?
npm uninstall -g react-native
npm install -g react-native-cli
I say this, because I kept making the error of installing react-native instead of react-native-cli.
export PATH="/Users/my-mac/Library/Android/sdk/platform-tools":$PATH
./adb reverse tcp:8081
./adb start-server
./adb devices
I've been in this situation or days, no solution yet, so I had to downgrade to Expo#19.0.0, and it worked
if you like to follow my steps:
in package.json update devDependencies:
"jest-expo": "19.0.0"
"react-native-scripts": "1.0.0"
in package.json update dependencies:
"expo": "19.0.0"
in app.json update the sdkVersion to 19.0.0
In my case, I would use npm start or react-native start and it would install the debug version of my app just fine, but the packager wouldn't start.
I found out it was because another process was using my 8081 port.
Check what processes are using that port if you're not specifying another port with lsof -i tcp:8081 in terminal, or any other tool to find out what processes are using what port.