gpt4 book ai didi

angular - 将 Moment 与 Angular 库 13 一起使用会导致错误

转载 作者:行者123 更新时间:2023-12-05 00:52:10 25 4
gpt4 key购买 nike

当我在 Angular 库中使用 moment.js(最新版本)时,我面临以下问题:

vendor.js:sourcemap:106713 ERROR TypeError: (moment__WEBPACK_IMPORTED_MODULE_2___namespace_cache || (intermediate value)(intermediate value)) 不是函数。例如,当我在浏览器中调试 moment().year() 时,它可以工作。

任何人都可以有一个想法,这个错误的原因是什么?也许是 EcmaScript 版本。

我将不胜感激。

> "compilerOptions": {
> "declaration": false,
> "downlevelIteration": true,
> "experimentalDecorators": true,
> "lib": [ "es6", "dom" ],
> "mapRoot": "./",
> "module": "esnext",
> "skipLibCheck": true,
> "moduleResolution": "node",
> "outDir": "../dist/out-tsc",
> "sourceMap": true,
> "target": "ES2015",
> "typeRoots": [
> "../node_modules/@types"
> ],

最佳答案

devdocs有解决这个问题的办法:

所以,你需要在库 tsconfig.lib.json 和项目 tsconfig.json 中添加:

"compilerOptions": {
...
"allowSyntheticDefaultImports": true,
...
}

然后使用语法从'moment'导入时刻;

关于angular - 将 Moment 与 Angular 库 13 一起使用会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70595835/

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