google-chrome - 如何让 chrome devtools 识别 moment.js

标签 google-chrome google-chrome-devtools momentjs

我正在开发ionic2项目。我刚刚开始使用 moment.js 但遇到了一个奇怪的问题。 我已通过 npm 安装:npm install moment -S

然后我在我的代码中使用了它:

import moment from 'moment'
...
let x = moment()
debugger

在控制台上我遇到了这个有趣的问题:

> x
< Moment {_isAMomentObject: true, _isUTC: false, _pf: {…}, _locale: Locale, _d: Wed Jun 27 2018 12:06:23, …}
> y = moment()
< VM770:1 Uncaught ReferenceError: moment is not defined
    at eval (eval at Phase (phase.ts:13), <anonymous>:1:1)
    at new Phase (phase.ts:13)
    at new Stage (stage.ts:10)
    at new HomePage (home.ts:39)
    at createClass (core.es5.js:10795)
    at createDirectiveInstance (core.es5.js:10621)
    at createViewNodes (core.es5.js:11971)
    at createRootView (core.es5.js:11876)
    at callWithDebugContext (core.es5.js:13007)
    at Object.debugCreateRootView [as createRootView] (core.es5.js:12468)

为什么我无法在控制台中使用 moment?

最佳答案

可以像这样从浏览器控制台获取它:

fetch('https://momentjs.com/downloads/moment.min.js')
    .then(response => response.text())
    .then(text => eval(text))

Then you could use it normally there

关于google-chrome - 如何让 chrome devtools 识别 moment.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51058881/

相关文章:

css - 带有指针事件和鼠标滚动的 Chrome 错误?

javascript - 谷歌浏览器扩展 : is it possible to get console output (js errors, console.log 等)

javascript - 如何让 moment.js 将日期 '1234 56 78' 视为无效日期?

javascript - 使用开始月份和结束月份的时刻获取一系列月份

html - 试图删除 index.html 文档,但在我刷新页面时仍然存在

javascript - 无法立即在弹出窗口内立即创建 'press' 刚刚创建的按钮。我必须关闭弹出窗口,然后再次打开它(chrome-extension 弹出窗口)

google-chrome - 谷歌浏览器在控制台中不显示错误

google-chrome - 自定义 Chrome 网络检查器的外观

javascript - 如何将 C# 使用的日期时间格式字符串转换为 moment.js 使用的格式?

javascript - 如何在 ContextMenu Click Chrome 扩展上运行脚本