Skip to content
This repository has been archived by the owner on Jan 16, 2018. It is now read-only.

Webpack and request module #3

Closed
pltod opened this issue Aug 26, 2014 · 7 comments
Closed

Webpack and request module #3

pltod opened this issue Aug 26, 2014 · 7 comments

Comments

@pltod
Copy link

pltod commented Aug 26, 2014

Great configurations shown in this project!

I have one question regarding consumption of https://github.com/mikeal/request.
When using webpack with application that uses request module I am getting something like:

ERROR in .//request/request.js
Module not found: Error: Cannot resolve module 'net' in
@ ./
/request/request.js 32:10-24

ERROR in .//request//forever-agent/index.js
Module not found: Error: Cannot resolve module 'tls' in
@ .//request//forever-agent/index.js 7:10-24

Is there a way to make webpack and request working together ?

@sokra
Copy link
Member

sokra commented Aug 26, 2014

I don't think this library is intended for in-browser usage...

@pltod
Copy link
Author

pltod commented Aug 26, 2014

Yes originally the library is not intended to work in the browser but now it works. I am using it inside React components to make HTTP calls to node.js server. As far as I know both request and superagent (https://github.com/visionmedia/superagent) can be used as alternatives to jQuery AJAX

I guess most people that are using React are not interested of using jQuery so they need something to communicate with the server. The theory for isomorphic apps :) - http://www.slideshare.net/spikebrehm/2014-0313fluent - says that we have environment agnostic libs (this is the case with request) and shimmed per environment (this is the case for superagent - it has browser property inside package.json to denote browser script that must be included during the build)

I just tried to use superagent instead of request....the webpack build now does not have errors but have warnings.

I am really curious what is the best approach of using one of these in the browser with webpack...

@sokra
Copy link
Member

sokra commented Aug 26, 2014

Ok than it should ignore net and tls in the browser field in the package.json. You propably want to submit a PR to request adding this field.

{
  "browser": {
    "net": false,
    "tls": false
  }
}

Or you can do it globally in the webpack configuration with:

{
  node: {
    net: "empty",
    tls: "empty"
  }
}

@pltod
Copy link
Author

pltod commented Aug 26, 2014

It works with 'node' parameter in webpack configuration. Thanks for the fast answer.

@pltod pltod closed this as completed Aug 26, 2014
@lai32290
Copy link

This is help for me! Thanks for you

@nrempel
Copy link

nrempel commented Apr 22, 2016

@sokra

{
  "browser": {
    "net": false,
    "tls": false
  }
}

Does not seem to be a part of the package.json spec. I can't see any documentation here https://docs.npmjs.com/files/package.json.

Is this is a convention that webpack uses?

Thanks.

**Edit:

Is it related to this spec? https://github.com/defunctzombie/package-browser-field-spec

@thg303
Copy link

thg303 commented Nov 26, 2016

any practical solution for this issue? or I have to push the 'eject' and leave the starter?

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

No branches or pull requests

5 participants