node.js - Babel Transpiler 无法与 Nodemon 一起运行
问题描述
问题:
无法将 Babel Transpiler 与 Nodemon 一起使用
细节:
在 package.json 我有:
"scripts": {
"start": "nodemon --exec babel-node --presets=es2015 -- src/app.js"
},
"dependencies": {
"nodemon": "^1.18.4"
},
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0"
}
当我运行npm start
我的理解是 nodemon 应该启动保存并运行 babel 转译器;但是,我在终端中得到以下信息。
错误:需要 Babel“^7.0.0-0”,但加载了“6.26.3”。如果你确定你有一个兼容的@babel/core 版本,很可能你的构建过程中加载了错误的版本。检查此错误的堆栈跟踪以查找第一个未提及“@babel/core”或“babel-core”的条目,以查看调用 Babel 的内容。
我认为这是由babel-cli
6.26 的依赖引起的,但是当我删除它时,它会发出声音:
[nodemon] failed to start process, "babel-node" exec not found
通过好的 ol' google 机器搜索,我看到其他一些设置更复杂的人,他们的解决方案似乎在我的脑海中飞过。
娱乐步骤:
运行
npm init -y
&npm i nodemon
按照此处的说明进行操作:https ://babeljs.io/setup#installation (nodemon) selected
npm install @babel/core --save-dev
当我被警告说没有安装核心时运行。跑
npm start
解决方案
使用 nodemon 运行 Babel 时,您需要包含这些包。
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/node": "^7.0.0",
"nodemon": "^1.18.4"
}
然后将您的 npm 运行脚本调整为:
"start": "nodemon app/index.js --exec babel-node app/index.js"
感谢 Babel Slack 频道的回答!
推荐阅读
- macos - 将自签名证书作为受信任的根证书添加到 Apple 钥匙串
- java - 依赖项的Maven依赖
- ruby-on-rails - Rails api POST 测试不允许我访问 json 对象
- c++ - 添加两个数字作为链表
- mysql - 在 MySQL 的父子关系中强制执行“收藏夹”的最佳方法是什么?
- signal-processing - 复数乘法指令Hexagon DSP
- java - 带有java模块的springframework ldap核心问题
- asp.net - 无法加载模板:(HTTP 状态:未定义未定义)在 ASP.Net 中的捆绑缩小后
- c++ - 结构中的 C/C++ 指针
- c - 我的代码中有多个错误,我不明白