Forum Stats

  • 3,815,965 Users
  • 2,259,119 Discussions


fetch in before_build hook?

Venkata Rahul S
Venkata Rahul S Member Posts: 36 Blue Ribbon

Before I build my application, I want to create a configuration file, contacting a specific internal configuration system whic exposes the configuration data for the build using a REST API.

So, I am customizing the before_build hook, but am unable to include the fetch library.

  1. Apparently, Node includes the MDN Fetch library only from v17 and onwards. So for earlier versions of NodeJS, this option is ruled out.
  2. Another way of looking at this is that somewhere within the OJET library itself, a fetch library is presumably in use. The existence of a RESTDataProvider hints so. So I can use that library. But what exatly should I write into the require instruction at the top of the before build hook is not clear.
  3. Add node-fetch to the library but that may be sub-optmial, because this is needed for build time only.

What is the way out? 2 seems the obvious choice but can someone please help me with the name of the library to be imported?



  • There are multiple ways of doing HTTP requests in Node. You are correct that Fetch was only added in the more recent release. You need to make sure you understand the difference between running in Nodejs(local filesystem) and in the Browser JavaScript engine. They are different environments.

    The hook scripts are Nodejs scripts that run during built time from our local Operating System. The JET runtime (application) is running in the browser and uses the browsers JS engine, not Nodejs.

    Take a look at Axios or just plain old XHR code when working with Nodejs.