javascriptnode.jsmernbabel-nodebabel-cli

babel-node --presets node '.' is not recognized as an internal or external command,


this is the dependencies in package.json

{
  "name": "whatsapp",
  "version": "1.0.0",
  "description": "whatsapp-clone-in-mern-stack",
  "main": "server.js",
  "scripts": {
    "start": "./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "someone",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.23.0",
    "babel-cli": "^6.26.0",
    "babel-preset-node8": "^1.2.0",
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "moment": "^2.29.1",
    "mongoose": "^6.0.14"
  }
}

code in server.js file

    import App from "express";
    import connectDB from "./dbConnection";
     const app = new App();
    
     const PORT = 3001;
    
     const startServer = () => {
         Promise.all([connectDB()]).then(() => {
             app.listen(PORT);
             console.log(`Server started on port ${PORT}`);
         });
     };
    
     startServer();

code in index.js file

import mongoose from "mongoose";

const DB_CONNECTION_URL = "mongodb://localhost:27017/test";

const connectDB = () => {
    console.log("DB trying to connect on " + new Date());
    const options = {
        keepAlive: 1,
        autoReconnect: true,
        poolSize: 10,
        useNewUrlParser: true,
        useUnifiedTopology: true,
    };
    return mongoose.connect(DB_CONNECTION_URL, options);
};

export default connectDB;

error in console

    whatsapp@1.0.0 start C:\Users\krish\onedrive\desktop\whatsapp_clone-mern_Stack\whatsapp-clone\server
    > ./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js
    
    '.' is not recognized as an internal or external command,
    operable program or batch file.
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! whatsapp@1.0.0 start: `./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the whatsapp@1.0.0 start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\krish\AppData\Roaming\npm-cache\_logs\2021-11-30T

09_26_47_364Z-debug.log

Learning from YouTube tutorials, I tried to make a whatsapp clone. I wanted to use babel cli and babel node to start the server in order to connect the database, so I wrote this code { "./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js" } in the scripts, but it displays the above error. Please help me.


Solution

  • write this

    "scripts": {
        "start": "node ./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js",
        "test": "echo \"Error: no test specified\" && exit 1"
      }, 
    

    instead of this

    "scripts": {
            "start": "./node_modules/babel-cli/bin/babel-node.js --presets node8 ./server.js",
            "test": "echo \"Error: no test specified\" && exit 1"
          },