You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ERROR in ./~/stripe/lib/stripe.js
Module not found: Error: Cannot resolve module 'child_process' in ~\node_modules\stripe\lib
@ ./~/stripe/lib/stripe.js 24:11-35
ERROR in ./~/stripe/lib/StripeResource.js
Module not found: Error: Cannot resolve module 'fs' in ~\node_modules\stripe\lib
@ ./~/stripe/lib/StripeResource.js 14:31-44
If I understand correctly, these are two built-in modules that ship with node.js. Isn't webpack supposed to be able to provide a web-equivalent?
What do you recommend I do in this case?
Reacted by Georgii Glinskij, Yining Shi, Dmitriy Pushkov, Florian Rudin, htbkoo, Misu Szijjarto-Nagy, John Weisz, Luiz Marcelo Santos, Letmeouted, Hai Pham Hoang and 1 more
Isn't webpack supposed to be able to provide a web-equivalent?
Pretty difficult to spawn a process and access the filesystem in the web... So there is no replacement for these modules. Propably means you can't use this module in a browser...
yes you can do that and hope that the module doesn't use any of the methods from this modules.
The proper course is the ask the module author to make the module browser compatible. The author can add browser: { fs: false, child_process: false } to the package.json to tell webpack that it's ok for the module to get an empty object for these modules.
Reacted by Idan Chetrit, Jamie Birch, euclidesmarques, Nicolò Savioli, Ph.D., Bailey Blankenship, Nick Mitchell, Hadrien Beaufils and vin123
Reacted by FakeBounce, Lynnmn, Mohamed Aboelmaatey, Dylan Gattey, Alauddin Afif Cassandra, Brian Kim and RuchitaCrawl
Is it possible to add this to the official documentation (i.e. "How to handle 3rd-party libraries with unresolved dependencies")? Otherwise, I assume other users will open issues asking the same question for different libraries.
@TomHarker Can you open a Stack Overflow question for that and link there? My understanding is that you can't tell that without running a file (not enough metadata) in an environment.
Here is the stackoverflow question. It just seems odd that people are happy to use node to build and manage a project with node at a system level, then in the same breath expect to use it in the web project they are making.
@TomHarker Yeah. I think some of this has to do with history. npm started backend-only and the frontend portions were sort of bolted in so people didn't give any conscious thought to this on specification level. I guess in ideal world you could tell the difference based on package.json metadata alone but that's not likely to happen. 😄
Activity
sokra commentedon Jan 31, 2015
Pretty difficult to spawn a process and access the filesystem in the web... So there is no replacement for these modules. Propably means you can't use this module in a browser...
cowwoc commentedon Jan 31, 2015
What is the proper course of action?
I read elsewhere that I can do this:
but is there a better approach (keeping in mind that I can't modify the 3rd-party library)?
sokra commentedon Jan 31, 2015
yes you can do that and hope that the module doesn't use any of the methods from this modules.
The proper course is the ask the module author to make the module browser compatible. The author can add
browser: { fs: false, child_process: false }to thepackage.jsonto tell webpack that it's ok for the module to get an empty object for these modules.cowwoc commentedon Jan 31, 2015
Sounds good.
Is it possible to add this to the official documentation (i.e. "How to handle 3rd-party libraries with unresolved dependencies")? Otherwise, I assume other users will open issues asking the same question for different libraries.
sheerun commentedon Nov 26, 2015
If you build for electron, you can add child_process to external modules
pksjce commentedon Sep 7, 2016
This issue was moved to webpack/webpack.js.org#107
TomHarker commentedon Mar 30, 2017
How are you supposed to know if a module is browser compatible? I'm trying to build for NW.js
bebraw commentedon Mar 31, 2017
@TomHarker Can you open a Stack Overflow question for that and link there? My understanding is that you can't tell that without running a file (not enough metadata) in an environment.
TomHarker commentedon Mar 31, 2017
http://stackoverflow.com/questions/43128454/importing-and-using-node-modules
Here is the stackoverflow question. It just seems odd that people are happy to use node to build and manage a project with node at a system level, then in the same breath expect to use it in the web project they are making.
bebraw commentedon Mar 31, 2017
@TomHarker Yeah. I think some of this has to do with history. npm started backend-only and the frontend portions were sort of bolted in so people didn't give any conscious thought to this on specification level. I guess in ideal world you could tell the difference based on package.json metadata alone but that's not likely to happen. 😄
cesargdm commentedon Jul 15, 2017
@sheerun how do you define that?
sheerun commentedon Jul 16, 2017
I don't remember now, but probably "externals" field for webpack 1, and following for webpack 2: https://webpack.js.org/configuration/externals/
wagenaartje commentedon Aug 5, 2017
Add
Fix problem with webpack build for browser
kdenaeem commentedon Apr 3, 2018
@wagenaartje is that code to be added in the javascript of the website?
Is it supposed to added in the methods or somewhere like that?
Fix problem with webpack build for browser