Recommand · December 8, 2021 0

React-native: [nodemon] starting `babel-node src`, "babel-node" is not recognized as an internal or external command, while npm run dev

I’m using nodemon to start an example with a hello world in a React Native app. But my app keeps crashing because it does not recognize the "babel-node" command when I execute "npm run dev". The error output is:

[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node src`
"babel-node" is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...

How fix this error?

My package.json:

{
  "name": "frontend",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "babel src -d dist",
    "dev": "nodemon src --exec babel-node"
  },
  "keywords": [],
  "dependencies": {
    "@babel/plugin-proposal-class-properties": "^7.16.0",
    "@babel/plugin-proposal-private-property-in-object": "^7.16.0",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/native": "^6.0.6",
    "@react-navigation/stack": "^6.0.11",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "expo": "^43.0.1",
    "expo-file-system": "~13.0.3",
    "expo-linear-gradient": "^10.0.3",
    "expo-status-bar": "~1.1.0",
    "express": "^4.17.1",
    "morgan": "^1.10.0",
    "mysql2": "^2.3.3",
    "native-base": "^3.2.1",
    "radio-buttons-react-native": "^1.0.4",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "^0.64.2",
    "react-native-animatable": "^1.3.3",
    "react-native-dropdown-picker": "^5.1.21",
    "react-native-gesture-handler": "^1.10.3",
    "react-navigation": "^4.4.4",
    "react-navigation-shared-element": "^3.1.3",
    "react-navigation-stack": "^2.10.4",
    "styled-components": "^5.3.3",
    "styled-system": "^5.1.5",
    "swagger-jsdoc": "^6.1.0",
    "swagger-ui-express": "^4.2.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.16.0",
    "@babel/core": "^7.16.0",
    "@babel/node": "^7.16.0",
    "@babel/plugin-proposal-private-methods": "^7.16.0",
    "@babel/preset-env": "^7.16.4",
    "@babel/register": "^7.16.0",
    "babel-core": "^7.0.0-bridge.0",
    "nodemon": "^2.0.15"
  },
  "private": true
}

My index.js (in the src folder: src/index.js):

const greet = 'hello world'
console.log(greet)

My .babelrc archive:

{
    "presets":[
        // "@babel/preset-env"
        ["@babel/preset-env", { "loose": true }]
    ],
    "plugins": [
        ["@babel/plugin-proposal-class-properties", { "loose": true }],
        ["@babel/plugin-proposal-private-methods", { "loose": true }],
        ["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
    ]
}

First of all, Thanks