ERROR in ./~/parse/~/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Cannot resolve module 'child_process' in /Users/aksonov/UPDT/sf/node_modules/parse/node_modules/xmlhttprequest/lib
@ ./~/parse/~/xmlhttprequest/lib/XMLHttpRequest.js 15:12-36
It seems I can't use require('xmlhttprequest').XMLHttpRequest for web?
The xmlhttprequest module shims the XMLHttpRequest-API to node (for whatever reason - it's the ugliest API ever ^^). You wan't to bundle your code for the browser, and the browser doesn't know about processes and child processes.
There are two solutions to this problem:
parse why they're using the xmlhttprequest module instead of node's http module.xmlhttprequest module which just exports the original XMLHttpRequest objectmodule.exports = XMLHttpRequest;
Btw: This is not a webpack-dev-server issue.
according to @jhnns 's answer, adding this to the externals in webpack.config.js fixed Parse for me.
externals:[{
xmlhttprequest: '{XMLHttpRequest:XMLHttpRequest}'
}]
Hi @jhnns I tried to use an alias for the xmlhttprequest module. The way I did is I created a dummy a.js file and I put module.exports = XMLHttpRequest; in it. In my make-webpack-config.js I have
var alias = {
xmlhttprequest$: "./a.js"
};
Now when I start production server I have error
module.exports = XMLHttpRequest;
^
ReferenceError: XMLHttpRequest is not defined
It seems webpack cannot find XMLHttpRequest (the original one supposedly is supported by the browser?) Is there something I'm missing?
Thanks!
this worked for me
const nodeExternals = require('webpack-node-externals');
module.exports = {
//... webpack configs..
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder from bundling
};
Most helpful comment
according to @jhnns 's answer, adding this to the externals in webpack.config.js fixed Parse for me.