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

XMLHttpRequest require to use node target in webpack #4

Closed
kresli opened this issue Jul 24, 2017 · 6 comments
Closed

XMLHttpRequest require to use node target in webpack #4

kresli opened this issue Jul 24, 2017 · 6 comments

Comments

@kresli
Copy link

kresli commented Jul 24, 2017

I need to add target: 'node' to my webpack config otherwise I've got this error

ERROR in ./~/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'fs'
ERROR in ./~/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'child_process'

I would suggest to use https://www.npmjs.com/package/whatwg-fetch. I can create a pull request

@wagenaartje
Copy link
Owner

wagenaartje commented Jul 24, 2017

Hmm. I'm not sure why this is happening. Travis CI seems to handle it fine. Are you sure using the linked library would fix this? What node version are you using?

@kresli
Copy link
Author

kresli commented Jul 24, 2017

node -v
v8.1.3

I created a sample repo. https://github.com/kresli/stocks-js-test. You can test it with npm run build

@wagenaartje
Copy link
Owner

wagenaartje commented Jul 24, 2017

Yep. Managed to reproduce it. I'm not really familiar with what target: 'node' does specifically. But you might be right in that we need to seek a new request module.

@wagenaartje
Copy link
Owner

wagenaartje commented Jul 24, 2017

I'm quite embarassed to say I never knew fetch existed. If you're sure that this doesn't create any problems (and if you're sure it fixes the current one), please do switch from XMLHttpRequest to the listed library.

It seems to work like a charm (run from page with appropiate content security policy):

fetch('https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo')
  .then(function (response) {
    return response.json()
  }).then(function (body) {
    console.log(body)
  });

@wagenaartje
Copy link
Owner

I made a version with fetch. I tested it, and it seems to have fixed the problem 👍

@parvezk
Copy link

parvezk commented Nov 19, 2017

Follow this approach, it will solve the problem:
webpack/webpack-dev-server#66

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

No branches or pull requests

3 participants