waterwheel.js icon indicating copy to clipboard operation
waterwheel.js copied to clipboard

Server-side requests are broken

Open beejunk opened this issue 6 years ago • 5 comments

When attempting to make requests using Node.js on the server side, Waterwheel throws this error:

ReferenceError: XMLHttpRequest is not defined

I believe this is because the module is exporting the Webpack bundle from the dist directory, and something about the bundle is tricking Axios into incorrectly believing that it is being run from the browser and not the server.

A workaround is to import Waterwheel directly from the lib folder:

const waterwheel = require('./node_modules/waterwheel/lib/waterwheel')

This is not ideal, but it solves the problem.

beejunk avatar Mar 06 '18 00:03 beejunk

@beejunk Thank you, I was struggling with this and couldn't figure out what's happening

drupalshift avatar Mar 07 '18 06:03 drupalshift

@beejunk Thank you, this worked for us as well.

import Waterwheel from 'waterwheel/lib/waterwheel'

danlaush avatar Apr 13 '18 01:04 danlaush

This also appears to be a problem specifically with 1.3.7 now pointing at the dist file (as of this commit)

In 1.3.6, the main export was "lib/waterwheel.js" which just worked. So either roll back or use the explicit 'waterwheel/lib/waterwheel'` path in your projects...

geelen avatar Apr 13 '18 02:04 geelen

In 1.3.6, the main export was "lib/waterwheel.js" which just worked. So either roll back or use the explicit'waterwheel/lib/waterwheel'` path in your projects...

The problem is that using 'lib/whaterwheel.js' doesn't just work in all situations. For instance, the create-react-app build process fails when using 'lib/waterwheel.js', because the build script will not minify any third-party library that is not compiled to ES5 (see here for details.) This was previously the case with Waterwheel, and the change to exporting the 'dist' folder fixed that issue. Unfortunately, it created this issue as a result. So I don't think that rolling back would necessarily be a good idea.

It may be better if the module exported code that has only been compiled from the source to ES5, instead of exporting code that has been completely bundled and uglified by Webpack.

beejunk avatar Apr 13 '18 18:04 beejunk

The same cannot import this lib in polymer 3

dravenk avatar Oct 10 '18 06:10 dravenk