angular - 如何立即修复导出的 unix
问题描述
在我的项目中将我的角度版本更新为 9.1.4 后,我收到了这个错误
"export 'unix' (imported as 'moment') was not found in 'moment'
如何解决这个问题。我的 ts 代码是import * as moment from 'moment';
time
时间戳
const timeString = moment.unix(time / 1000).utc().format();
解决方案
我试图在 stackblitz 上从头开始启动一个新项目。一切都按预期工作。
请点击此链接以查找更多信息。
// package.json
{
"name": "angular",
"version": "0.0.0",
"private": true,
"dependencies": {
"@angular/animations": "9.1.0",
"@angular/common": "^9.1.0",
"@angular/compiler": "^9.1.0",
"@angular/core": "^9.1.0",
"@angular/forms": "^9.1.0",
"@angular/platform-browser": "^9.1.0",
"@angular/platform-browser-dynamic": "^9.1.0",
"@angular/router": "^9.1.0",
"core-js": "^3.6.4",
"moment": "^2.25.1", // moment.js
"rxjs": "^6.5.4",
"tslib": "^1.10.0",
"zone.js": "^0.10.3"
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.0",
"@angular/cli": "~7.0.2",
"@angular/compiler-cli": "~7.0.0",
"@angular/language-service": "~7.0.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.1"
}
}
// app.component.ts
import { Component, OnInit } from '@angular/core';
import * as moment from 'moment';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
timeString: string;
private time = Date.now();
ngOnInit() {
this.timeString = moment.unix(this.time / 1000).utc().format(); // your example
}
}
推荐阅读
- java - 无法从spring项目连接到mysql数据库
- openssl - 如何使用 OpenSSL API 检查证书或 CRL 文件的格式?
- highcharts - Highchart - Angular 9:如何将所有图表导出为单个 pdf?
- orm - GraphQL 和二进制格式 - ORM 问题
- c# - 无法将数据写入文件。所有 System.IO 方法都不起作用。Xamarin.Forms
- python - TypeError: 'int' object is not iterable, 不知道为什么会这样
- r - 在 ggplot2 中使用 aes 映射设置 geom_vline 线型和大小
- ruby-on-rails - Rails - 标记无效的嵌套字段
- c# - 从 C# 中的返回对象中删除属性
- dialogflow-es - 如何结束我对助手的自定义操作?