React-native: [NODEMON] starting `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'
我正在使用 nodemon 在 React Native 应用程序中启动一个带有 hello world 的示例。但是我的应用程序一直崩溃,因为当我执行 "npm 运行 dev" 时它无法识别“babel-node”命令。错误输出为:
[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...
如何解决这个错误?
我的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
}
我的index.js(在src文件夹中:src/index.js):
const greet = 'hello world'
console.log(greet)
我的 .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 }]
]
}
首先,谢谢
对我有用的解决方案是删除包-lock.json 和 运行:npm install @babel/node -g。 :)
我正在使用 nodemon 在 React Native 应用程序中启动一个带有 hello world 的示例。但是我的应用程序一直崩溃,因为当我执行 "npm 运行 dev" 时它无法识别“babel-node”命令。错误输出为:
[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...
如何解决这个错误?
我的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
}
我的index.js(在src文件夹中:src/index.js):
const greet = 'hello world'
console.log(greet)
我的 .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 }]
]
}
首先,谢谢
对我有用的解决方案是删除包-lock.json 和 运行:npm install @babel/node -g。 :)