gpt4 book ai didi

javascript - MomentJS 在 babel 编译后返回全局未定义

转载 作者:行者123 更新时间:2023-11-27 22:50:11 26 4
gpt4 key购买 nike

我在 MomentJS 中使用 fullCalendar 插件,在 babel 编译后,我遇到了关于 MomentJS 的错误:

global is undefined

您知道问题可能出在哪里吗?

谢谢!

最佳答案

我相信我已经找到了这个问题的解决方案。我在与 Moment 不同的库上遇到错误。 Heroku 日志报告

Module not found: Error: Cannot resolve module 'json-loader' in /app/node_modules/sentiment/lib

但是,在 babel 编译(通过 webpack)之后,我在控制台中遇到了相同的错误

Uncaught ReferenceError: global is not defined

当我美化压缩代码时,该行抛出错误

x=global.Object.prototype

我追溯到图书馆 lodash。 Webpack 使用 lodash 来运行 babel。基于this conversation thread中的信息通过将 lodash 版本从 3.5.0 版本更新到 4.13.1 解决了该问题。

控制台错误和“找不到模块”错误都消失了。

关于javascript - MomentJS 在 babel 编译后返回全局未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38118780/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com