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
I'm attempting to load request using Webpack and am seeing this error:
I have seen that this is supposed to work in the browser using browserify and was curious what I'm doing wrong. Maybe browserify processes the dependencies differently from webpack which is causing this issue. Any ideas?
Reacted by Michael Rossetti, Maja Korajčević, Robert Komaromi, Bucky Schwarz, Nick Olinger, Monte Hayward, Dan Dascalescu, Matt Darby, Riderman de Sousa Barbosa, Mariusz Kaliński and 118 more
Reacted by Codelab Studios, Charles Swanberg and Uzair Jalil
Reacted by Codelab Studios, markhc, Aldi Zhupani, Scott Mansell, the_mason45 and Uzair Jalil
Reacted by Codelab Studios, Clément Parent, Mikhail S., JackyLee, waleedshkt and Uzair Jalil
I figured it out. The problem is that Webpack requires some extra config unlike browserify due to it's more barebones nature. See my example branch and diff for how I got the tests to run successfully.
My plan is to turn that into it's own karma test and submit a PR so others can use it as an example. Also, it may uncover future issues as development progresses.
Reacted by Philipp Otto and Sir.Nathan (Jonathan Stassen)
Reacted by WebBug, Jeremy Gayed, Nicolai Kamenzky, 微笑, Stefanie Doll, Jeff Shamley, nyura123, Danny Clarke, Alexey Boklin, Miguel Angel Mayori and 11 more
Reacted by Avare Kodcu, Matías Fornés, B3none, Pavel Tugolukov, Doug Molineux, Víctor Gámez, slowhop-it, Cord Slatton, kumorig, Youth and 30 more
Reacted by Daniel Kao, Brandon Brown and Andy Spock
The solution: install json-loader so that webpack can handle *.json files. Then add that loader and a new node object to your webpack.config.js like so:
Reacted by Édouard Lopez, Changsheng Wu, Lando Löper, PhiXL, Andrew Thomas, A, Tyson, Sergei C., Joe Krump, pandajk and 208 more
Reacted by sohil chhabriya, Konstantin Falko, alanimgur, La Griffe 🦅, Mukul, 微笑, Ramil Zakirov, Johnny, Edwin Karanja, Jenny Yang and 10 more
Reacted by Chalice Stevens, Matthew Epler, Matt Elliott, Chen Li, Alfian Busyro, why-always-bob, ranchoX, Duncan Steenburgh, Antonio Estrada, Ryan Marinaro and 46 more
Reacted by Davis Ford, Ped, Phil Ensminger, Victor Magarlamov, sohil chhabriya, Luís Costa, alanimgur, Achilles Rasquinha, La Griffe 🦅, Kostia Vyrodov and 28 more
Reacted by Will McFarland, Cole Chamberlain, Matthew Epler, Robert Komaromi, Joel Jackson, Dan Dascalescu, Matt Brandly, McCall Alexander, Raul Rene Lepșa, Donna and 32 more
Reacted by Joel Jackson, Kabir Lal, Dmitry Sky, Brandon Durham, Mateus Dal Bianco, Aliaksandr Ihnashevich, Amanda, Janzen Zarzoso, Ben Liyanage and Jboucly
Reacted by Yohann Bacha, Vladimir Baranov, Shir Brass, Alex Mills, Margarita Gómez, Natali and Ben Liyanage
For peeps who have trouble with storybook and don't want to replace storybook's original webpack config, you can extend it by creating .storybook/webpack.config.js and add:
// Load the default config generator.constgenDefaultConfig=require('@kadira/storybook/dist/server/config/defaults/webpack.config.js');module.exports=function(config,env){constnewConfig=genDefaultConfig(config,env);// Extend to resolve fs issuesnewConfig.node={fs: 'empty'};returnnewConfig;};
Reacted by Arkodeb Maity, Jack O'Connor, Keisuke KITA, mkulig and RyujiTAKEHARA
I ran into this issue and it was because I was running a dual client/server config for server side rendering. The server-side rendering config was marked as target: 'node', while the client config didn't have one specified. I added target: 'web' to the client config and the error went away.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I had the same issue trying to use jQuery with Nuxt (or Node), the problem was I was importing jQuery and Bootstrap and added jsdom to solve it but did not work. I solved it importing libraries directly in head section of nuxt.config.js, another way is to set client mode in nuxt config plugins, I hope it help someone.
Activity
jaredmcdonald commentedon Apr 6, 2015
+1, also seeing this
Output:
pho3nixf1re commentedon Apr 6, 2015
I figured it out. The problem is that Webpack requires some extra config unlike browserify due to it's more barebones nature. See my example branch and diff for how I got the tests to run successfully.
master...pho3nixf1re:webpack-tests
My plan is to turn that into it's own karma test and submit a PR so others can use it as an example. Also, it may uncover future issues as development progresses.
jaredmcdonald commentedon Apr 7, 2015
Yeah, found the same, thanks. For anyone else that stumbles across this, the relevant webpack docs are here: http://webpack.github.io/docs/configuration.html#node
vvo commentedon Apr 14, 2015
@jaredmcdonald thanks a lot :)
simov commentedon Apr 24, 2015
@pho3nixf1re it would be great if you submit a PR about testing request with webpack (additional test, not in place of the browserify one) 👍
pho3nixf1re commentedon Apr 24, 2015
Yes! I intend to. I only replaced it in my branch as a quick proof of concept. I'll get on that this weekend.
varatep commentedon Apr 27, 2015
Adding the json webpack loader unfortunately did not fix this for me.
screendriver commentedon May 19, 2015
Same issue here.
The solution: install
json-loaderso that webpack can handle *.json files. Then add that loader and a newnodeobject to yourwebpack.config.jslike so:webpack.config.js
Add webpack karma config as reference
Add webpack karma config as reference
kilometers commentedon Jun 14, 2015
Adding the
node: { ... }object avoids the error, but then I can't useconsolein the browser. Is there a way around this?kilometers commentedon Jun 14, 2015
I just figured it out:
Add webpack karma config as reference
Add webpack karma config as reference
mattdell commentedon Jul 21, 2015
This was a huge help for me. Thanks to all above.
20 remaining items
brickgale commentedon Dec 13, 2016
+1
Thanks!
trentmillar commentedon Jan 11, 2017
I made a small change using what @screendriver & @kilometers provided (thanks!).
Webpack complained if there was an empty extension, however, I don't think this would be required for most.
Fix import of build-in node modules
tuanh118 commentedon Feb 21, 2017
For peeps who have trouble with storybook and don't want to replace storybook's original webpack config, you can extend it by creating
.storybook/webpack.config.jsand add:fix dependency errors
chandrasekarb commentedon May 12, 2017
Using this above code error has been solved but
fs.writeFile('/home/react-hello-world/test.txt', 'aaa', function(err) { alert(err); });fs.writeFile is not working please give any solution.
lk22 commentedon Aug 3, 2017
@chandrasekarb try set fs to true instead of 'empty'
FDiskas commentedon Oct 18, 2017
target: 'node',worked for me 🏬wsrast commentedon Nov 6, 2017
I ran into this issue and it was because I was running a dual client/server config for server side rendering. The server-side rendering config was marked as target: 'node', while the client config didn't have one specified. I added target: 'web' to the client config and the error went away.
add setting of webpack for use request-promise
stale commentedon Nov 23, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
reconbot commentedon Apr 1, 2019
Request is now in maintenance mode and wont be merging any new features or addressing this bug. Please see #3142 for more information.
jonalxh commentedon Jun 5, 2020
I had the same issue trying to use
jQuerywithNuxt(or Node), the problem was I was importingjQueryandBootstrapand addedjsdomto solve it but did not work. I solved it importing libraries directly inheadsection ofnuxt.config.js, another way is to setclient modein nuxt config plugins, I hope it help someone.