简体   繁体   中英

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 . When I run npm start , errors shows up. yarn start gives more details error message shown there.

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)); ^

ReferenceError: [BABEL] C:\\Users\\max\\Documents\\react-calculator\\server\\server.js: Unknown option: base.0. Check out h ttp://babeljs.io/docs/usage/options/ for more information about 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}]] }

For more detailed information on preset configuration, please see 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 .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.

Does anyone see what's going on here and how to solve it?

Use create-react-app. It is way simpler than configuring babel and creating React projects the old way. To use it, go to the directory you want your project to be in, and type in your terminal: 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. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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