簡體   English   中英

在Electron應用程序啟動時,將依賴項與'export'語句一起使用會中斷

[英]Using a dependency with an 'export' statement breaks at Electron app startup

我正在嘗試使用electronic-webpackatlaskit構建一個電子應用程序。

我已經設置了最小的倉庫來重現該問題: fstephany / bug-report-electron-webpack

這是我的package.json

{
  "name": "electron-webpack-quick-start",
  "version": "0.0.0",
  "license": "MIT",
  "esm": "auto",
  "scripts": {
    "dev": "electron-webpack dev",
    "compile": "electron-webpack",
    "dist": "yarn compile && electron-builder",
  },
  "dependencies": {
    "source-map-support": "^0.5.12",
    "esm": "^3.2.25",
    "@atlaskit/navigation-next": "6.3.0"
  },
  "devDependencies": {
    "electron": "5.0.4",
    "electron-builder": "^20.44.4",
    "electron-webpack": "^2.7.1",
    "webpack": "~4.35.0"
  } 
}

而我的src/renderer/index.js僅加載外部依賴項:

import { LayoutManager } from "@atlaskit/navigation-next";

let app = document.getElementById("app");
let layoutManager = LayoutManager;
console.log(app);
console.log(layoutManager);

當我使用$ yarn dev運行該應用程序時。 我在Electron窗口的Web控制台中收到一個錯誤:

Uncaught /home/fstephany/Code/Play/new-electron-webpack-project/node_modules/@atlaskit/navigation-next/index.js:2
export { default as ContainerHeader } from './components/presentational/ContainerHeader';
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:85:7)
    at createScript (vm.js:266:10)
    at Object.runInThisContext (vm.js:314:10)
    at Module._compile (internal/modules/cjs/loader.js:742:26)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:820:10)
    at Module.load (internal/modules/cjs/loader.js:677:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:609:12)
    at Function.Module._load (internal/modules/cjs/loader.js:601:3)
    at Module.require (internal/modules/cjs/loader.js:715:19)
    at require (internal/modules/cjs/helpers.js:14:16)

SyntaxError: Unexpected token export使我認為Babel轉堆缺少某些內容。 尤其是當@ atlaskit / navigation-next 5.0.0版本的發行說明中明確提到:

從所有流模塊中刪除ES5

在所有@atlaskit軟件包中刪除CJS支持

作為一項重大變化,所有@atlaskit軟件包都將刪除cjs發行版,並且只會發行esm。 這意味着將翻譯所有分布式代碼,但仍將包含導入和導出聲明。

關於如何解決此問題的任何想法? 我嘗試了不同的babel配置,但是我想轉圈...

我通過在electronic-webpack的whilelisted模塊設置中放置了atlaskit依賴項來使其工作。 有關上下文,請參見提交

"electronWebpack": {
  "whiteListedModules": ["@atlaskit/navigation-next"]
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM