我們有一個正在運行的反應應用程序,需要我爲其生成電子。按照Here的說明添加我的Main.js文件後。我的電子扔了上面的錯誤。經歷後,我發現我的電子不與ES6和我index.js反應低於運行[SyntaxError:意外的令牌導入]時,應用程序發生錯誤
import React from 'react';
import ReactDOM from 'react-dom';
import Root from './_store/root';
ReactDOM.render(<Root/>, document.getElementById('root'));
術語,當我改變從上面的代碼進口,電子拋出另一個錯誤invalid token >
我的理解是從<Root/>
。
下面是我如何運行我的電子
./node_modules/.bin/electron .
部分我的package.json是
"main": "src/index.js",
"scripts": {
"test": "npm run test:eslint && npm run test:unit",
"test:eslint": "webpack --config webpack.config.dev.js",
"test:unit": "mocha --compilers js:babel-core/register ./src/**/__tests__/*.js",
"test:watch": "npm test -- --watch",
"test:coverage": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha ./src/_common/__tests__/*.js",
"start": "node server.js",
"build": "npm run clean && npm run build:webpack",
"translate": "bash fetch-translation.sh"
}
我的反應中反應過來,反應過來,終極版工作正常執行的應用程序。
和我webpack.config
module.exports = {
devtool: 'eval',
entry: [
'./src',
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'app.js',
publicPath: '/',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
include: path.join(__dirname, 'src'),
}, {
test: /\.js$/,
loader: 'eslint-loader',
include: path.join(__dirname, 'src'),
}],
},
};
唯一的問題是我的電子這我試圖生成一個桌面應用程序。任何幫助,將不勝感激。
和我相依
"devDependencies": {
"babel-core": "^6.4.0",
"babel-eslint": "^5.0.0-beta6",
"babel-loader": "^6.2.1",
"babel-plugin-react-intl": "^2.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-function-bind": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^3.1.0",
"eslint-loader": "^1.2.0",
"eslint-plugin-react": "^3.15.0",
"expect": "^1.13.4",
"expect-jsx": "^2.2.2",
"express": "^4.13.3",
"istanbul": "^0.4.2",
"json-loader": "^0.5.4",
"mocha": "^2.3.4",
"react-addons-perf": "^0.14.6",
"react-addons-test-utils": "^0.14.6",
"webpack": "^1.12.11",
"webpack-dev-middleware": "^1.2.0",
"webpack-hot-middleware": "^2.6.0"
}
發生這個錯誤是因爲babel沒有爲電子編譯代碼。我之前沒有使用過電子,但是我發現了一個可能有用的回購:https://github.com/suisho/example-electron-babel/ –