webpack — how to include nodejs module for js/jsx in non-current directory

720
January 22, 2017, at 2:38 PM

Trying to include a npm module in my jsx.

My dir structure is something like:

   app/
     node_modules/
     webpack.config.json
     package.json
     main.js
   react/
     myreact1.jsx
     myreact2.jsx

Note: purposely do not want a package.json & node_modules in react/

I've figured out that I have to do this for webpack2 config:

   resolve: {
     modules: ["node_modules", path.resolve(__dirname, "node_modules")
   }

This forces webpack to first always try ./node_modules, then default to app/node_modules

However, for the module I'm trying to include in myreact.jsx (npm: "request"), this module uses alot of native node libraries like "fs" and "tls", etc.

webpack now gives me this error:

Abbreviated error:

ERROR in ./~/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/myproj/app/node_modules/request/lib'
 @ ./~/request/lib/har.js 3:9-22
 @ ./~/request/request.js
 @ ./~/request/index.js
 @ ../react/myreact1.jsx
 @ ./app.jsx
 @ ./main.js

Display-error-details version of the error:

ERROR in ./~/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/myproj/app/node_modules/request/lib'
resolve 'fs' in '/myproj/app/node_modules/request/lib'

How do I get webpack to correctly find the native node modules 'fs', 'tls', 'net' etc for 'request' module and the other 3rd party modules it uses inside it's own node_modules?

Thanks for any help

Rent Charter Buses Company
READ ALSO
Node.js server gives Cross-Origin Request Blocked

Node.js server gives Cross-Origin Request Blocked

My Nodejs server code is running on an AWS instance

723
How to scale backend Firebase service

How to scale backend Firebase service

I am building an application with a decent amount of Firebase service code running in the backendIt is possible that this App will end up reaching thousands and possibly hundreds of thousands of users

408
Rails server command JavaScript runtime error

Rails server command JavaScript runtime error

I just started learning Ruby on rails and everything works fine until when I run the server also I reinstalled Nodejs and no locki'm on windows 10

588
Layout is called with express-partials even when layout:false

Layout is called with express-partials even when layout:false

In my layoutejs, I use the variable user as follows:

315