'Getting error "babel" is not recognized as an internal or external command,

I have a simple tests.js file that I wish to follow up with a source map file. I have tried initiating the dependencies yet the prompt shows the error. If anyone could specify the problem and the solution would be grateful ^^

tests.js

var add = (...arr) => {
    return arr.reduce((sum, el) =>{
        return sum+el;
    }, 0)
}
console.log(add(1,2,3));

I've tried these commands at first

npm install -g babel-cli

npm install babel-preset-es2015

babel tests.js --out-file tests.dist.js --source-maps --presets=es2015

But received the same error. I have followed another solution from the community but it still didn't work. The solution was to remove node_modules and reinitiate the dependencies.

npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/node

and add "start": "nodemon --exec babel-node index.js", in the dependencies. I checked the node_modules and it had the existence of these files too.

node_modules/.bin/babel-node

node_modules/.bin/babel-node.cmd - windows only

node_modules/@babel/node/bin/babel-node.js

The solution I followed Still, I couldn't figure out how to solve this issue. This is my first time working with node and babel. My node version is v16.13.1

Edited

Folder Structure

Y:.
|   index.html
|   package-lock.json
|   package.json
|   tests.js
|   tree.txt
|   
\---node_modules
    |   .package-lock.json
    |   
    +---.bin
    |       babel
.....

It's huge!

package.json

{
  "dependencies": {
    "@babel/cli": "^7.16.8",
    "@babel/core": "^7.16.12",
    "@babel/preset-env": "^7.16.11"
  }
}

.babelrc

{
    "presents": [
        "@babel/preset-env"
    ]
}

./node_modules/@babel/cli/bin/babel.js

require("../lib/babel");

After using bash for the command -

./node_modules/@babel/cli/bin/babel.js example.js --out-file main.dist.js

The error

Error: Unknown option: .presents. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options.
    at throwUnknownError (Y:\babel work\node_modules\@babel\core\lib\config\validation\options.js:133:27)
    at Y:\babel work\node_modules\@babel\core\lib\config\validation\options.js:118:5
    at Array.forEach (<anonymous>)
    at validateNested (Y:\babel work\node_modules\@babel\core\lib\config\validation\options.js:94:21)
    at validate (Y:\babel work\node_modules\@babel\core\lib\config\validation\options.js:85:10)
    at Y:\babel work\node_modules\@babel\core\lib\config\config-chain.js:209:34
    at cachedFunction (Y:\babel work\node_modules\@babel\core\lib\config\caching.js:60:27)
    at cachedFunction.next (<anonymous>)
    at evaluateSync (Y:\babel work\node_modules\gensync\index.js:251:28)
    at sync (Y:\babel work\node_modules\gensync\index.js:89:14) {
  code: 'BABEL_UNKNOWN_OPTION'
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source