acquia / waterwheel.js

A generic JavaScript helper library to query and manipulate Drupal 8 via core REST and JSON API
https://github.com/acquia/waterwheel.js
233 stars 26 forks source link

Server-side requests are broken #77

Open beejunk opened 6 years ago

beejunk commented 6 years ago

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.

drupalshift commented 6 years ago

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

danlaush commented 6 years ago

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

import Waterwheel from 'waterwheel/lib/waterwheel'
geelen commented 6 years ago

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...

beejunk commented 6 years ago

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.

dravenk commented 5 years ago

The same cannot import this lib in polymer 3