target:“node-webkit” fails with Uncaught ReferenceError: require is not defined

BUG

What is the current behavior?
target: ‘node-webkit’ fails with Uncaught ReferenceError: require is not defined

If the current behavior is a bug, please provide the steps to reproduce.
Download the source code here : https://github.com/react-boilerplate/react-boilerplate/releases/tag/v3.4.0
change the line in internals/webpack/webpack.base.babel.js
from

target: ‘web’, // Make web variables accessible to webpack, e.g. window

to

target: ‘node-webkit’, // Make web variables accessible to webpack, e.g. window

or

target: ‘node’, // Make web variables accessible to webpack, e.g. window

$npm install
$npm start

and open http://localhost:3000 in your browser.

What is the expected behavior?
Code runs good with target:’web’ config. Expected behavior is not getting the “ReferenceError: require is not defined” error.

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

node Version : v9.7.1
Browser: Chrome 64 also the same result with nw.js
Webpack Version : “2.2.0-rc.3” and “3.0.0”
Operating System : Macos High Sierra (10.13.3)

Here package json

Author: Fantashit

1 thought on “target:“node-webkit” fails with Uncaught ReferenceError: require is not defined

  1. This happened to me, too with webpack 6.4.1 – for anyone else encountering this issue:
    You have to add

    "node-remote": "http://localhost/*",
    

    to your package.json file so that files served via the dev server have access to the node and NW.js APIs as well.

    If you, like me, are new to all of this and are using typescript as well, don’t for get to also

    npm install -D @types/webpack-env
    

    and

    npm install -D @types/node
    

    to prevent any TS compilation errors. I hope this will save others the headache I had trying to get a setup with NW.js, webpack-dev-server and TypeScript to work.

Comments are closed.