Transpile with babel CLI - javascript

I want to transpile several js files that are in ES6 to be compatible with chrome, but it seems the docs in http://babeljs.io/docs/usage/cli/ are not accurate.
After doing the first few steps I type in the console: babel and get:
You have mistakenly installed the babel package, which is a no-op in
Babel 6. Babel's CLI commands have been moved from the babel package
to the babel-cli package.
npm uninstall babel
npm install --save-dev babel-cli
See http://babeljs.io/docs/usage/cli/ for setup instructions.
And even if I run those two commands it mention, I still get the same error.
So my question is how are you supposed to transpile files with Babel and CLI?

A bit old question, but in case someone ended here through Google like me:
I had the same problem, just ran
npm install --save-dev babel-cli
in a new and completely empty directory in order to test something and could not transpile when calling babel through npx with the same error. I didn't have Babel installed globally, but after a while I noticed npm didn't create the package.json file. So I deleted everything, created empty package.json with just
{
}
installed babel-cli again (npm now added dev dependency to the json file) and now it works fine.

Related

How to compile typescript?

If I use tsc it doesn't work. If I don't have tsc but have typescript, it still doesn't work. What can I do?
You have to install the typescript library like this.
npm install typescript --save-dev
Then npx tsc command will work.
What you have installed is a deprecated library called tsc
Check here. So you may have to remove that first with the following command
npm uninstall tsc

Grep package.json dependency versions and interpolate them in a MakeFile

I am trying to get the current dependencies and devDependencies versions that are set in the package.json file so that when the MakeFile is run for a new user, it installs the versions listed there and not just the latest version. So for the example below, instead of just saying npm install #applitools/eyes-testcafe we would grab the version 1.16.1 from the package.json and interpolate it there in the MakeFile like ${eyes_version} or something like that.
Any idea on how to do this? Thanks!
package.json
"devDependencies": {
"#applitools/eyes-testcafe": "^1.16.1",
"testcafe": "^1.18.6",
"testcafe-reporter-xunit": "*"
}
MakeFile
install-testcafe: npm ffmpeg applitools testcafe
# Installs all dependencies necessary for testcafe and node to run.
npm:
npm install
# Installs the ffmpeg video recorder. This is recursive as sometimes it doesn't install automatically.
ffmpeg:
npm install #ffmpeg-installer/ffmpeg
# Installs the applitools dependency. This is recursive as sometimes it doesn't install automatically.
applitools:
npm install #applitools/eyes-testcafe
# Installs TestCafe globally. This is recursive as sometimes it doesn't install automatically.
testcafe:
sudo npm install -g testcafe
Since you are using jq,
jq '.devDependencies["#applitools/eyes-testcafe"]' package.json
Is it useful?
I question the validity/usefulness of using a Make wrapper around NPM. You're wrapping a build tool in a build tool. Why? I'm guessing to make it more familiar to developers coming from a C/Make ecosystem. But mixing Make and NPM like this confuses Node/NPM developers, and NPM scripts can run CLI commands just like Make does.
Is npm i really more complicated than make npm? Seems like this information is better off in a README, and Make developers should be educated on how to use NPM (e.g. you can run CLI commands from inside NPM scripts). Adding Make scripts isn't adding any value here, but YMMV, maybe this is particularly useful inside your org.
Also don't use sudo when running npm.

If babel is already listed in `dev-dependencies` for jest, why do I need to install it separately?

While setting up my newest project, npm seemed to install babel-core and babel-jest automatically on running npm install --save-dev jest.
Since npm's default behavior is to install dev dependencies on installing with --save-dev option, why do the docs specify installing babel again - https://facebook.github.io/jest/docs/en/getting-started.html#using-babel

How do I fix missing #angular/Core modules?

I can not run the Angular 2 project.
What I tried:
- running the project by using npm install and npm start | does not work
- I cloned quickstart from the github and replaced with my src folder and I still get the "can not find module in #angular/core"
Here is the full console output: https://www.dropbox.com/s/5plmqrjd6ge0lta/error.txt?dl=0
Many people will come here. I have had the same problem. Do not panic. You are probaly following the tutorial of tutorialspoint.
Just install the core again using NPM
npm install #angular/core
There was/is a bug in certain versions of npm that causes installed modules to disappear when using npm install someModule ... or npm install someModule --save-dev
This was apparently an issue if the module being installed was from a GitHub repo and lacked a specific commit hash to reference for the installation. Although the issue was marked "closed" and the repo archived several months ago at v5.6.0, I ran into the problem today w/the latest npm 6.4.0
In my case, doing npm install rxjs completely removed the #angular/core module, along with my #ionic-native plugins, and anything else I'd installed individually (and then it failed to actually/properly install rxjs anyway!!)
Tip: copy your existing npm modules folder as a backup before starting updates or removing it entirely & trying to npm install.
You can manually install to your project via npm install #angular/core, but depending on the npm version (or the angle of the moon at that precise moment, who knows) be aware that you might wind up with other missing dependencies.
Also try npm install #angular/core && npm install ... Apparently the additional npm install helps replace the randomly deleted/missing modules in some cases.

babel react issues finding modules

I have a small react jsx file that needs to be compiled to js.
I install babel and the presets like so in the directory with the js file
npm -g install babel-cli
npm install babel-preset-es2015 babel-preset-react
My script does this
babel --presets es2015,react input.js -o output.js
Everything works.
Reboot the machine and re-run the build. It fails.
Each time I reinstall babel and the presets to get it to work.
I am not a js dev and looking up the similar questions list and a google search for this issue returns 25 different ways of "fixing" the issue. This seems like a basic task, why is there so much noise around it and what is the right way to add this to a larger non-javascript build process .
You have to install the presets globally.
Do this
Create a new folder and move you input.js to that folder
Do npm init
Do npm i babel without -g
Do npm install babel-preset-es2015 babel-preset-react
Open the console at that location
Run ./node_mudules/.bin/babel --presets es2015,react input.js -o output.js

Categories