JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – 无法通过npm脚本运行babel“babel:command not found”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
开始我跑了:
npm install --save-dev babel-cli
npm install --save-dev babel-preset-es2015
npm install --save-dev babel-preset-stage-0

这是我的package.json:

{
      "scripts": {
        "build": "babel src -d dist"
      },"devDependencies": {
        "babel-cli": "^6.6.5","babel-core": "^6.7.2","babel-preset-es2015": "^6.6.0","babel-preset-stage-0": "^6.5.0"
      }
    }

这是我的.babelrc文件:

{
  "presets": ["es2015","stage-0"]
}

我的文件结构是这样的

- Root
    - src
        - client 
        - server
        - test  
    - dist 
    - package.json

我从根文件夹调用npm run build.我期望它将源文件夹编译到dist文件夹中.它运行,然后我得到这个错误:

> babel src -d dist

sh: babel: command not found

npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v5.8.0
npm ERR! npm  v3.7.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! redacted@1.0.0 build: `babel src -d dist`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the redacted@1.0.0 build script 'babel src -d dist'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do,this is most likely a problem with the redacted package,npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     babel src -d dist
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs redacted
npm ERR! Or if that isn't available,you can get their info via:
npm ERR!     npm owner ls redacted
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/user/redacted/npm-debug.log

所以你可以看到,我已经安装了babel-cli,我已经安装了预设,我认为一切都是按照babel文档顺序的.

有人有什么想法,为什么它不会工作?我可能会错过一个babel npm文件吗? “babel src -d dist”不正确吗?

感谢您的任何帮助,您可以提供!

做了另一个文件夹,并按照相同的步骤,它的工作完美.由于某种原因,它不能在此目录中工作.

解决方法

您是否运行“npm install”安装开发包?

大佬总结

以上是大佬教程为你收集整理的javascript – 无法通过npm脚本运行babel“babel:command not found”全部内容,希望文章能够帮你解决javascript – 无法通过npm脚本运行babel“babel:command not found”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。