Hey everyone, I’m stuck with a problem in Zapier. I’m trying to use Moment.js in my script, but it’s not working. The docs say it should be available, but when I try to import it like this:
var moment = require('moment');
I get this error:
Bargle. We hit an error creating a run javascript. :-( Error:
Error: Cannot find module 'moment'
And if I don’t include that line, I get a ReferenceError saying moment isn’t defined. Has anyone else run into this? How did you get Moment.js working in your Zapier scripts? I’m pretty confused since the docs say it should just work. Any help would be awesome!
yo, had the same issue. turns out you don’t gotta import moment at all in zapier. it’s already there, just use it like moment().format('whatever'). if that don’t work, try updating your zap or hit up zapier support. they’re usually pretty good about helpin out.
I’ve been there, and it can be frustrating when the docs don’t match reality. In my experience with Zapier, you don’t actually need to import Moment.js explicitly. It’s already available in the global scope.
Try using it directly without the require statement:
If that doesn’t work, double-check that you’re using the Code by Zapier action and not a different JavaScript step. Also, make sure your Zap is up to date, as older versions might have different behavior.
If you’re still having issues, you could try using the built-in Date object instead. It’s not as feature-rich as Moment.js, but it might be sufficient for basic date operations.
Let me know if this helps or if you need more guidance!
I encountered a similar issue when working with Zapier scripts. As others have mentioned, Moment.js is indeed pre-loaded in the Zapier environment. However, I found that occasionally, the global moment object isn’t recognized immediately.
A workaround that worked for me was to wrap the moment usage in a try-catch block:
try {
const formattedDate = moment().format('YYYY-MM-DD');
// Rest of your code using moment
} catch (error) {
console.log('Error using moment:', error);
// Fallback to native Date object if needed
}
This approach allows you to handle potential errors gracefully and provides a safety net. If you’re still experiencing issues, I’d recommend reaching out to Zapier support for further assistance.