babel-cli issues with npm - javascript

I am using babel to build a part of my library and I'm running into issues when i run babel commands through npm.
I have an npm script called build that calls:
{
"prebuild": "rm -rf && mkdir dist",
"build": "babel src/index.js -o dist/index.js"
}
I have run the actual babel command itself in my command line and it works.
However when I do npm run build from my command line it says
The CLI has been moved into the package 'babel-cli'
npm also says that it is that specific line that is failing.
I have already tried the following:
Restart my terminal.
Install babel v5 because I read that v6 split a lot of its functionality.
npm rebuild.
Delete my node_modules and npm install
Any other ideas? as to why npm fails at running this command?

Install babel#5 globally (npm install babel#5 --global) as well as locally: npm install babel#5 --save-dev

Related

NPM return “bash command not found” when I try to get a package version

I have installed the package.json that includes nodemon package (and others)
#npm list --depth 0
├─┬ nodemon#2.0.7
but the command #nodemon -v return a -bash error: "nodemon command not found”
I cant start my server.js with nodemon, the same error, but all works with #node server.js
Any idea? Thnks
With a local install
You can use npx nodemon filename.js
If you want to install it globally
With npm npm install nodemon -g or with yarn yarn global add nodemon, that way you can use nodemon directly (nodemon filename.js)

npm scripts to run packages global or local

You can think that I will install nodemon with below script:
npm install --save-dev nodemon#1.0.0
So it will install the nodemon package to my project locally.(not global)
I will also add the npm script:
{
"scripts": {
"nodemonscript": "nodemon yourscript.js"
}
}
So if I execute "npm run nodemonscript" it will run the nodemon from my project local node_modules.(not global)
So somehow I will decide to also install nodemon 2.0.0 globally.
I will run this script to install package:
npm install -g nodemon#2.0.0
Finally I have nodemon#1.0.0 from my local project and nodemon#2.0.0 globally.
So if I execute
"npm run nodemonscript"
again from my local project root which have below script:
{
"scripts": {
"nodemonscript": "nodemon yourscript.js"
}
}
Here are my questions:
1)Which version will be execute 1.0.0 or 2.0.0?
2)I want to use always local nodemon package. Which way is more safe?
3)Are all the npm packages have the same behaviour for npm scripts?
4)And my last question is how npx will behaviour for this situation?

How to install nodemon Nodejs on macOS? nodemon keeping show : command not found

Currently I already install nodemon with command npm install -g nodemon. And I got Permissions issue, so I do command with sudo npm install -g nodemon and i did it. But when I make "nodeman" command was always show nodemon: command not found.
If for any reasons you are unable to set a Global PATH then under your current project directory, run
npm install nodemon --save-dev
then under "scripts" in your package.json file, add "start": "nodemon app.js" like this -
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}
then run
npm start
If you need to install nodemon globally on mac OS, try
sudo npm install -g nodemon.
Then you'll have to enter your password. Once the installation is completed successfully, run
nodemon -v
to check nodemon version on terminal.
According to this, Create a new directory to store your global packages. So that there is no permission issue.
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Edit your .profile or .bash_profile to add the new location to your PATH:
export PATH=~/.npm-global/bin:$PATH
Then install the package without sudo:
npm install -g nodemon
If you want to install global nodemon use SUDO, because if you need to be a global user, you need to be a super user
The other answer is correct but my advice is that it's better to not install packages globally if you can help it, this makes your application self sufficient without relying on the environment and avoids versioning issues between applications.
npm install -D nodemon
You can now execute nodemon from scripts in package.json:
"scripts": {
"start": "nodemon src/index.js"
}
Or you can execute it yourself using npx if you're in that directory from the terminal. npx executes local scripts, e.g. npx nodemon --inspect ./src/index.js 8080
Just run these commands and the error will get solved.
Specially for MAC People:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Enter your laptop password
npm install i -g nodemon or npm install -g nodemon
All set .....🎉

do I have to install npm for every new project?

I have NPM installed in my PC how to use it for a new project?
or do I have to install npm for every new project?
NPM is extremely useful, but, when you install it, you install it globally. It comes with Node JS, so when you install Node JS, you should have npm installed(type npm -v to see the version and whether npm is installed).
"npm init" creates a package.json for your folder, which contains all the information about the version number, the name of the project, and some other information. In package.json, you can add dependencies, which basically say your project relies on that npm package.
"npm install" will install all the packages specified in package.json, and, if you want to install something specific, you would type "npm install ".

After installation of Gulp: “no command 'gulp' found”

After installing gulp.js via npm, I receive a no command 'gulp' found error when running the gulp command from the same directory it was installed into.
When looking under the node_modules/.bin/ directory, I can see the gulp executable there.
Is there something wrong with my npm installation?
That's perfectly normal.
If you want gulp-cli available on the command line, you need to install it globally.
npm install --global gulp-cli
See the install instruction.
Also, node_modules/.bin/ isn't in your $PATH. But it is automatically added by npm when running npm scripts (see this blog post for reference).
So you could add scripts to your package.json file:
{
"name": "your-app",
"version": "0.0.1",
"scripts": {
"gulp": "gulp",
"minify": "gulp minify"
}
}
You could then run npm run gulp or npm run minify to launch gulp tasks.
I solved the issue without reinstalling node using the commands below:
$ npm uninstall --global gulp gulp-cli
$ rm /usr/local/share/man/man1/gulp.1
$ npm install --global gulp-cli
I actually have the same issue.
This link is probably my best guess:
nodejs vs node on ubuntu 12.04
I did that to resolve my problem:
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
I solved the issue removing gulp and installing gulp-cli again:
rm /usr/local/bin/gulp
npm install -g gulp-cli
if still not resolved try adding this to your package.js scripts
"scripts": { "gulp": "gulp" },
and run npm run gulp
it will runt gulp scripts from gulpfile.js
Installing on a Mac - Sierra - After numerous failed attempts to install and run gulp globally via the command line using several different instructions I found I added this to my path and it worked:
export PATH=/usr/local/Cellar/node/7.6.0/libexec/npm/bin/:$PATH
I got that path from the text output when installing gulp.
Tried with sudo and it worked !!
sudo npm install --global gulp-cli
I'm on lubuntu 19.10
I've used combination of previous answers, and didn't tweak the $PATH.
npm uninstall --global gulp gulp-cli
This removes any package if they are already there.
sudo npm install --global gulp-cli Reinstall it as root user.
If you want to do copy and paste
npm uninstall --global gulp gulp-cli && sudo npm install --global gulp-cli
should work
I guess --global is unnecessary here as it's installed using sudo, but I've used it just in case.
in my case there was only on issue, just put "gulp":"gulp" in the script portion, of package.json, and then use command npm run gulp.

Categories

Resources