我是React的新手,我正在尝试关注react official website上的例子。
在使用WebStorm OR intellij idea终极时运行计算器应用程序(index.js)
output of npm run start or npm start
我得到这个错误:
(function (exports, require, module, __filename, __dirname) { import React from 'react';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Process finished with exit code 1
我的问题是如何使用intellij idea ultimate运行这样的应用程序我尝试过:
npm install -g create-react-app
npm install -g eslint
npm install --save-dev babel-preset-es2015
npm install --save-dev babel-core babel-preset-es2015 babel-preset-react
npm install -g eslint babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype
并将以下内容添加到package.json:
"babel": {
"presets": [ "es2015", "react" ]
}
或者.babelrc
{
"presets": [ "es2015", "react" ]
}
我的问题是如何使用intellij idea ultimate package.json运行这样的应用程序
{
"name": "emoji-search",
"version": "0.1.0",
"private": true,
"homepage": "http://ahfarmer.github.io/emoji-search",
"devDependencies": {
"gh-pages": "^1.1.0",
"react-scripts": "^1.0.17"
},
"dependencies": {
"github-fork-ribbon-css": "^0.2.1",
"react": "^16.2.0",
"react-dom": "^16.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": "./node_modules/react-scripts/config/eslint.js"
},
"babel": {
"presets": [ "es2015", "react" ]
}
}
(我的问题是如何使用intellij idea ultimate运行这样的应用程序)
你可以像这个npm install --save-dev react-scripts
一样安装react-scripts。
然后,您将能够运行此命令:react-scripts start
位于项目的根目录(package.json所在的位置)。
如果您不想使用命令,可以在How to run a React app with Webstorm上学习本教程
基本上,要启动反应应用程序,您需要运行命令(npm start
);如果要使用webstorm开始按钮,则需要将其绑定到命令。从这个link: