【发布时间】:2019-03-11 11:48:29
【问题描述】:
问题:
无法在 Nodemon 中使用 Babel Transpiler
详情:
在 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 的内容。
我认为这是由 6.26 的 babel-cli 依赖引起的,但是当我删除它时,它会发出声音:
[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
【问题讨论】:
标签: node.js npm babeljs nodemon