Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot resolve module 'child_process' to build XMLHttpRequest #66

Closed
aksonov opened this issue Oct 7, 2014 · 5 comments
Closed

Cannot resolve module 'child_process' to build XMLHttpRequest #66

aksonov opened this issue Oct 7, 2014 · 5 comments
Labels

Comments

@aksonov
Copy link

aksonov commented Oct 7, 2014

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
@aksonov
Copy link
Author

aksonov commented Oct 7, 2014

It seems I can't use require('xmlhttprequest').XMLHttpRequest for web?

@jhnns
Copy link
Member

jhnns commented Oct 7, 2014

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:

  • Ask the maintainers of parse why they're using the xmlhttprequest module instead of node's http module.
  • Provide an alias for the xmlhttprequest module which just exports the original XMLHttpRequest object
module.exports = XMLHttpRequest;

Btw: This is not a webpack-dev-server issue.

@codeboyim
Copy link

according to @jhnns 's answer, adding this to the externals in webpack.config.js fixed Parse for me.

externals:[{
    xmlhttprequest: '{XMLHttpRequest:XMLHttpRequest}'
}]

@jeffyuans
Copy link

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!

@thiagoh
Copy link

thiagoh commented Dec 23, 2017

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
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants