gpt4 book ai didi

javascript - 忽略 moment.js 的 eslint 错误

转载 作者:行者123 更新时间:2023-11-30 11:30:55 36 4
gpt4 key购买 nike

我在我的 React 应用程序中添加 moment.js 作为外部资源,如下所示:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

当我在启用了 eslint 的代码文件中使用 moment 时,我收到了这个 eslint 错误:'moment' is not defined(no-undef )

这是我的 .jsx 文件-

constructor() {
super()
this.state = {
startDate: moment()
}
}
...

我的 eslintrc.yml 看起来像这样:

extends:
- jquery
- airbnb

parser: babel-eslint

parserOptions:
ecmaVersion: 6
ecmaFeatures:
experimentalObjectRestSpread: true
jsx: true
sourceType: "module"

env:
browser: true
node: true
jquery: true
...

最佳答案

如果你使用 webpack。 npm 安装时刻--保存 从时刻导入时刻;

或者您可以通过在同一行的 moment() 之后添加注释来禁用 linting。 //eslint-disable-line

关于javascript - 忽略 moment.js 的 eslint 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46258116/

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