简体   繁体   中英

Webpack Externals require not defined with Electron and Angular 4

I have a setup with Webpack , Electron , and Angular 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

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.

My webpack.config.js defines externals:

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:

import * as fs from 'fs';

You can read more on the solution in my article .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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