我正在使用Babel 7使用Parcel构建电子应用程序。基本上是this tutorial的修改版。
我正在使用基本的.babelrc:
{ "presets": [
["@babel/env", {
"targets": { "node": 7 },
"useBuiltIns": true
}],
"@babel/react"
],
"plugins": ["dynamic-import-node"]
}
这是我的package.json
{
"name": "appName",
"productName": "App Name",
"version": "3.0.0",
"license": "MIT",
"scripts": {
"react-start": "parcel -p 3000 app.html --out-dir build",
"react-build": "parcel build app.html --out-dir build --public-url ./",
"clean-build": "rm -rf build/ .cache dist/",
"build": "yarn clean-build && yarn react-build",
"start": "concurrently \"cross-env NODE_ENV=development yarn react-start\" \"wait-on http://localhost:3000 && electron . \""
},
"main": "./src/main.js",
"browserslist": "electron 1.6",
"build": {
"productName": "AppName",
"appId": "org.company.AppName",
"files": [
"node_modules/",
"app.html",
"main.js",
"package.json"
],
"dmg": {
"contents": [
{
"x": 130,
"y": 220
},
{
"x": 410,
"y": 220,
"type": "link",
"path": "/Applications"
}
]
},
"mac": {
"target": "dmg",
"icon": "build/icon.ico"
},
"win": {
"target": "nsis",
"icon": "build/icon.ico"
},
"linux": {
"target": [
"deb",
"AppImage"
],
"icon": "build/icon.ico",
"category": "Development"
},
"directories": {
"buildResources": "resources",
"output": "release"
}
},
"dependencies": {
"@babel/polyfill": "^7.4.4",
"@react/react-spectrum": "^2.22.0",
"babel-plugin-dynamic-import-node": "^2.3.0",
"electron-devtools-installer": "^2.2.4",
"electron-store": "^4.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.2",
"babel-plugin-dynamic-import-node-babel-7": "^2.0.7",
"concurrently": "^4.1.1",
"cross-env": "^5.2.0",
"electron": "^6.0.0",
"electron-is-dev": "^1.1.0",
"electron-log": "^3.0.7",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^17.1.1",
"eslint-plugin-compat": "^3.3.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.6.1",
"parcel-bundler": "^1.12.3",
"wait-on": "^3.3.0"
}
}
当我只运行React(react-build
和react-start
时,运行Electron(build
和{{ 1}})我从start
文件中获得了以下内容。
main.js
我尝试在 import path from 'path';
^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:722:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
at Module.load (internal/modules/cjs/loader.js:645:32)
at Function.Module._load (internal/modules/cjs/loader.js:560:12)
at loadApplicationPackage (/Users/lipton/symposium/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:109:16)
at Object.<anonymous> (/Users/lipton/symposium/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:155:9)
at Module._compile (internal/modules/cjs/loader.js:786:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
at Module.load (internal/modules/cjs/loader.js:645:32)
at Function.Module._load (internal/modules/cjs/loader.js:560:12)
和@babel/preset-env
之间切换(似乎无关紧要)。
我尝试跟踪电子文档,包裹文档或babel文档中的现有问题。我很困惑。
更新:尝试清除@babel/env
并重新安装。我正在使用ES6导入的渲染器中出现错误。如果仅将渲染器切换为ES5导入,则可以使用。