Best answer

Using glob.sync to load all resources

  • 20 December 2021
  • 1 reply
  • 223 views

Userlevel 1

Does anybody know why this won’t work once it was pushed to Zapier:

const glob = require('glob');
const path = require('path');

const myResources = {};
const myTriggers = {};


glob.sync('./resources/*.js').forEach( file => {
const resource = require(path.resolve(file));

if (resource.key) {
myResources[resource.key] = resource;
}
});


glob.sync('./triggers/*.js').forEach( file => {
const resource = require( path.resolve(file) );

if( resource.key ){
myTriggers[ resource.key ] = resource;
}
});

module.exports =
{
..
resources: myResources,
triggers:myTriggers,
authentication: require('./authentication')
}

 

MyResources and myTriggers is set correct local and while running the tests, but it won’t work after the push(*), while manually building up the resources data and requiring each one manually just works fine.

 

	resources: {
test1: require('./resources/test1'),
test2: require('./resources/test2'),
...
},

 

Is it a limit within the Zapier CLI integration?

 

(*)

Following error is returned when I try to use the action:

Error: Could not find the method to call: triggers.myHook.operation.performList

icon

Best answer by ikbelkirasan 22 December 2021, 14:19

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 7
Badge +12

Hi @DanielF - Zapier CLI performs some tree shaking when it builds the app before uploading it. So, any file that’s not imported using require will be ignored.

You can find the build output in the build/build.zip file. If you take a look inside it, you’ll not find the triggers and resources folders.

You can tell the Zapier CLI to include those folders by adding the following to the .zapierapprc file:

{
"id": your_app_id,
"key": "App...",
"includeInBuild": [
"resources/*",
"triggers/*"
]
}