简体   繁体   English

React-native:[NODEMON] 启动 `babel-node src`,“babel-node”未被识别为内部或外部命令,而我运行“npm run dev”

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

I'm using nodemon to start an example with a hello world in a React Native app.我正在使用 nodemon 在 React Native 应用程序中启动一个带有 hello world 的示例。 But my app keeps crashing because it does not recognize the "babel-node" command when I execute "npm run dev" .但是我的应用程序不断崩溃,因为当我执行“npm run dev”时它无法识别“babel-node”命令。 The error output is:错误 output 是:

[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:我的 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",
    "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):我的 index.js(在 src 文件夹中:src/index.js):

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

My.babelrc archive: My.babelrc 存档:

{
    "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首先,谢谢

The solution that worked for me was delete package-lock.json and run: npm install @babel/node -g.对我有用的解决方案是删除 package-lock.json 并运行:npm install @babel/node -g。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM