简体   繁体   中英

Error when replacing Moment.js with Luxon in Google Apps Script

I have a Google Apps script that uses Moment.js that I want to use Luxon instead. The following worked fine for using moment.js:

eval(UrlFetchApp.fetch('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.js').getContentText());

However, eplacing the URL with the CDN URL of Luxon like so:

eval(UrlFetchApp.fetch('https://cdn.jsdelivr.net/npm/luxon@3.0.3/build/global/luxon.min.js').getContentText());

Throws an error:

console.log(DateTime.now().toString());
ReferenceError: DateTime is not defined

Copying the minified file to luxon.gs also fails with the same error.

I have no idea if the problem is with something that changed in Luxon or a limitation of Apps Script — any ideas?

I copied the entire Luxon.js (non-minified) library into a.gs file and was able to use it:

console.log(luxon.DateTime.now().toLocaleString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM