简体   繁体   English

Webpack外部组件不需要使用Electron和Angular 4定义

[英]Webpack Externals require not defined with Electron and Angular 4

I have a setup with Webpack , Electron , and Angular 4 . 我使用WebpackElectronAngular 4进行了设置。 I searched and tried several approaches, however as I could not solve it, i am going to ask here. 我搜索并尝试了几种方法,但是由于无法解决,我将在这里提出问题。

When i run webpack, it compiles without errors, however in the browser's console i get 当我运行webpack时,它可以正确编译,但是在浏览器的控制台中

Uncaught ReferenceError: require is not defined
    at Object.128 (external "require('fs')":1)

I tried to include it in several ways: 我试图以几种方式包括它:

let fs = require("fs");

I had the same issue with path, child_process, etc. 我在path,child_process等方面也遇到了同样的问题。

My webpack.config.js defines externals: 我的webpack.config.js定义了外部组件:

module.exports = {
    "externals": {
        "electron": "require('electron')",
        "child_process": "require('child_process')",
        "fs": "require('fs')",
        "path": "require('path')",...
    }
}

UPDATE 更新

Is solved it. 解决了。 Since all Node functions are already provided through the Webpack externals, one does not have to require them but use them via imports like this: 由于已经通过Webpack外部提供了所有Node功能,因此不必强制要求它们,而是通过如下所示的导入来使用它们

import * as fs from 'fs';

You can read more on the solution in my article . 您可以在我的文章中阅读有关该解决方案的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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