简体   繁体   English

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

[英]npm start (or yarn start) error with babel when creating react applications

I am trying this article working on a react calculator I set my package.json with "start": "babel-node ./server/server.js" in the scripts . 我正在尝试这篇文章在"start": "babel-node ./server/server.js" 计算器上工作,我在scripts使用"start": "babel-node ./server/server.js"设置了package.json。 When I run npm start , errors shows up. 当我运行npm start ,出现错误。 yarn start gives more details error message shown there. yarn start显示更多详细信息错误消息。

max@DESKTOP-4J1U771 MINGW64 ~/Documents/react-calculator (master) $ yarn start yarn run v1.7.0 warning package.json: No license field $ babel-node ./server/server.js C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\transformation\\file\\logger.js:41 throw new Constructor(this._buildMessage(msg)); max @ DESKTOP-4J1U771 MINGW64〜/ Documents / react-calculator(master)$ yarn start yarn run v1.7.0 warning package.json:No license field $ babel-node ./server/server.js C:\\ Users \\ max \\ Documents \\ react-calculator \\ node_modules \\ babel-core \\ lib \\ transformation \\ file \\ logger.js:41抛出新的Constructor(this._buildMessage(msg)); ^ ^

ReferenceError: [BABEL] C:\\Users\\max\\Documents\\react-calculator\\server\\server.js: Unknown option: base.0. ReferenceError:[BABEL] C:\\ Users \\ max \\ Documents \\ react-calculator \\ server \\ server.js:未知选项:base.0。 Check out h ttp://babeljs.io/docs/usage/options/ for more information about options. 请访问h ttp://babeljs.io/docs/usage/options/了解有关选项的更多信息。

A common cause of this error is the presence of a configuration options object without the corresponding preset name. 导致此错误的常见原因是存在没有相应预设名称的配置选项对象。 Example: 例:

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

For more detailed information on preset configuration, please see https://babeljs.io/docs/en/plugins#pluginpresets-op tions. 有关预设配置的更多详细信息,请参阅https://babeljs.io/docs/en/plugins#pluginpresets-op tions。 at Logger.error (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\transformation\\file\\logger.js:41:11) at OptionManager.mergeOptions (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\transformation \\file\\options\\option-manager.js:226:20) at OptionManager.init (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\transformation\\file\\op tions\\option-manager.js:368:12) at File.initOptions (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\transformation\\file\\inde x.js:212:65) at new File (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\transformation\\file\\index.js:135 :24) at Pipeline.transform (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\transformation\\pipelin e.js:46:16) at Object.transformFileSync (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-core\\lib\\api\\node.js:152: 10) at compile (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-register\\lib\\node 在Logger.error(C:\\ Users \\ max \\ Documents \\ react-calculator \\ node_modules \\ babel-core \\ lib \\ transformation \\ file \\ logger.js:41:11)在OptionManager.mergeOptions(C:\\ Users \\ max \\位于OptionManager.init(C:\\ Users \\ max \\ Documents \\ react-calculator \\ node_modules \\下的Documents \\ react-calculator \\ node_modules \\ babel-core \\ lib \\ transformation \\ file \\ options \\ option-manager.js:226:20) Babel-core \\ lib \\ transformation \\ file \\ options \\ 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) Object.transformFileSync(C:\\ Users \\ max \\ Documents \\)上的Pipeline.transform(C:\\ Users \\ max \\ Documents \\ react-calculator \\ node_modules \\ babel-core \\ lib \\ transformation \\ pipelin e.js:46:16) 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) at loader (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\babel-register\\lib\\node.js:144:14) at Object.require.extensions.(anonymous function) [as .js] (C:\\Users\\max\\Documents\\react-calculator\\node_modules\\ babel-register\\lib\\node.js:154:7) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this > command. .js:118:20)在Object.require.extensions(匿名函数)的加载器(C:\\ Users \\ max \\ Documents \\ react-calculator \\ node_modules \\ babel-register \\ lib \\ node.js:144:14)中[as .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,以获取有关此>命令的文档。

Does anyone see what's going on here and how to solve it? 有人看到这里发生了什么以及如何解决吗?

Use create-react-app. 使用create-react-app。 It is way simpler than configuring babel and creating React projects the old way. 这比配置babel和使用旧方法创建React项目要简单得多。 To use it, go to the directory you want your project to be in, and type in your terminal: create-react-app [project-name]. 要使用它,请转到您想要项目所在的目录,然后在终端中键入:create-react-app [project-name]。 This will do all the configuring for you and make it easier for you. 这将为您完成所有配置,并使您更轻松。 The installation and configuration of React mentioned in the article is outdated, but you can still follow everything else in that tutorial. 本文中提到的React的安装和配置已经过时,但是您仍然可以按照该教程中的其他内容进行操作。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM