簡體   English   中英

在 Google Apps 腳本中將 Moment.js 替換為 Luxon 時出錯

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

我有一個使用 Moment.js 的 Google Apps 腳本,我想改用 Luxon。 以下適用於使用 moment.js:

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

但是,將 URL 替換為 Luxon 的 CDN URL,如下所示:

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

引發錯誤:

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

將縮小文件復制到 luxon.gs 也會失敗並出現相同的錯誤。

我不知道問題是出在 Luxon 中的某些更改還是 Apps 腳本的限制 - 有什么想法嗎?

我將整個 Luxon.js(非縮小)庫復制到 a.gs 文件中並且能夠使用它:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM