Angular- 不能使用命名空间 'moment' 作为类型
Angular- Cannot use namespace 'moment' as a type
编译代码时出现错误
import * as moment from "moment";
编译错误
ERROR in [at-loader] ./project/src/common/common.factory.spec.ts:72:40 TS2709: Cannot use namespace 'moment' as a type.
有什么建议吗
您需要导入没有别名的时刻。
import moment from 'moment';
此外,您可能需要添加选项 allowSyntheticDefaultImports 并在 tsconfig.json 文件中将其设置为 true
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
}
}
编译代码时出现错误
import * as moment from "moment";
编译错误
ERROR in [at-loader] ./project/src/common/common.factory.spec.ts:72:40 TS2709: Cannot use namespace 'moment' as a type.
有什么建议吗
您需要导入没有别名的时刻。
import moment from 'moment';
此外,您可能需要添加选项 allowSyntheticDefaultImports 并在 tsconfig.json 文件中将其设置为 true
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
}
}