#javascript #node.js #react-native #nodemon #babel-node
Вопрос:
Я использую nodemon, чтобы начать пример с hello world в приложении React Native. Но мое приложение продолжает сбой, потому что оно не распознает команду «вавилонский узел», когда я выполняю «npm run dev». Вывод ошибок является:
[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...
Как исправить эту ошибку?
Мой пакет.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 }] ] }
Прежде всего, Спасибо
Ответ №1:
Решение, которое сработало для меня, было удалить package-lock.json и запустить: npm install @babel/node-g. 🙂