创建React应用程序时,Babel出现npm start(或纱线启动)错误

时间:2018-07-20 10:34:03

标签: node.js reactjs npm babel yarnpkg

我正在尝试将本文用于a react calculator 我在"start": "babel-node ./server/server.js"中用scripts设置了package.json。运行npm start时出现错误。 yarn start提供了此处显示的更多详细信息错误消息。

  

max @ DESKTOP-4J1U771 MINGW64〜/ Documents / react-calculator(master)$   yarn start yarn run v1.7.0警告package.json:无许可证字段$   babel节点./server/server.js   C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ transformation \ file \ logger.js:41       抛出新的构造方法(this._buildMessage(msg));       ^

     

ReferenceError:[BABEL]   C:\ Users \ max \ Documents \ react-calculator \ server \ server.js:未知   选项:base.0。查看h ttp://babeljs.io/docs/usage/options/   有关选项的更多信息。

     

此错误的常见原因是配置的存在   选项对象,没有相应的预设名称。示例:

     

无效:{ presets: [{option: value}] }有效:{ presets: [['presetName', {option: value}]] }

     

有关预设配置的更多详细信息,请参阅   https://babeljs.io/docs/en/plugins#pluginpresets-op号。       在Logger.error(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ transformation \ file \ logger.j   s:41:11)       在OptionManager.mergeOptions(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ transformation   \ file \ options \ option-manager.js:226:20)       在OptionManager.init(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ transformation \ file \ op   tions \ option-manager.js:368:12)       在File.initOptions(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ transformation \ file \ inde   x.js:212:65)       在新文件(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ transformation \ file \ index.js:135   :24)       在Pipeline.transform(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ transformation \ pipelin   e.js:46:16)       在Object.transformFileSync(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-core \ lib \ api \ node.js:152:   10)       在编译时(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-register \ lib \ node.js:118:20)       在加载程序中(C:\ Users \ max \ Documents \ react-calculator \ node_modules \ babel-register \ lib \ node.js:144:14)       在Object.require.extensions。(匿名函数)[作为.js](C:\ Users \ max \ Documents \ react-calculator \ node_modules \   babel-register \ lib \ node.js:154:7)错误命令失败,并显示退出代码   1. info请访问https://yarnpkg.com/en/docs/cli/run,以获取有关此>命令的文档。

有人看到这里发生了什么以及如何解决吗?

1 个答案:

答案 0 :(得分:0)

使用create-react-app。这比配置babel和使用旧方法创建React项目要简单得多。要使用它,请转到您想要项目所在的目录,然后在终端中键入:create-react-app [project-name]。这将为您完成所有配置,并使您更轻松。本文中提到的React的安装和配置已经过时,但是您仍然可以按照该教程中的其他内容进行操作。祝你好运!