【发布时间】:2016-11-24 14:14:28
【问题描述】:
我使用以下命令在我的项目中本地安装了 Babel:
npm install babel-cli babel-core babel-preset-es2015 --save-dev
这在 package.json 中为我提供了以下输出:
{
"name": "my_project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "babel src -d lib"
},
"scripts": {
"build": "babel --presets es2015 src -d lib"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel": "^6.5.2",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-es2015": "^6.18.0",
"webpack": "^1.13.3"
},
"dependencies": {
"lodash": "^4.17.2"
}
}
我不确定,但看起来它安装成功了。但是当我尝试运行 npm run babel 时,我得到:
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "babel"
npm ERR! node v7.0.0
npm ERR! npm v4.0.2
npm ERR! missing script: babel
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
nam ERR! /Path/To/My/Project/npm-debug.log
为什么 Babel 不起作用?在 package.json 文件中包含:
【问题讨论】:
-
你在 webpack 配置中定义了吗?
-
如果没有,请查看(类似问题)的答案[stackoverflow.com/a/40776313/2902660]
标签: npm webpack command-line-interface babeljs