网站搜索

javascript - Babel 安装 - src 不存在


快速问题。我发现了类似的案例,但它们对我不起作用。

按照这个指南 https://babeljs.io/docs/setup/#installation 我正在尝试安装 Babel Cli。

但是从 package.json 中配置的命令运行 babel

"scripts": {
    "build": "babel src -d lib"
},

抛出一个错误

> babel src -d lib

src doesn't exist
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email  build: `babel src -d lib`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email  build script.
npm ERR! This is probably not a problem with npm. There is likely 
additional logging output above.

npm ERR! A complete log of this run can be found in:

运行命令 npm run build 时

我已经安装了 babel-preset-env 并配置了 .babelrc

npm 版本 6.1.0

你知道 src 不存在 是从哪里来的吗?谢谢!

答案#1

src 是包含你想要转换的文件的文件夹。你可以创建它并将你的文件移动到那里,或者更新命令以使用包含你文件的文件夹。

更多信息:https://babeljs.io/docs/usage/cli/#compile-directories