我正在尝试开始使用 Angular 2 CLI。
我想在我的项目中使用 moment.js,这是我所做的:
1. 使用 Angular CLI 创建项目。
2. 运行 npm install --save moment
3. 在 src 文件夹中运行 typings init
+ typings install --save moment
。
4. 将 moment 添加到系统模块中:
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
moment: {
map: 'node_modules/moment/moment.js',
type: 'cjs',
defaultExtension: 'js'
}
}
});
- 将
import * as moment from 'moment';
添加到所需组件中。 - 运行
ng serve
并得到以下错误信息:
[DiffingTSCompiler]:TypeScript 发现以下错误: app/angular-day-picker.ts(2,25):找不到模块“moment”。 错误:[DiffingTSCompiler]:TypeScript 发现以下错误: app/angular-day-picker.ts(2,25):找不到模块“moment”。 at DiffingTSCompiler.doFullBuild (/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:202:29) at DiffingTSCompiler.rebuild (/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:101:18) at DiffingPluginWrapper.rebuild (/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/lib/broccoli/diffing-broccoli-plugin.js:87:45) at /Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/broccoli/lib/api_compat.js:42:21 at lib$rsvp$$internal$$tryCatch (/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1036:16) at lib$rsvp$$internal$$invokeCallback (/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1048:17) at /Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:331:11 at lib$rsvp$asap$$flush (/Users/vioffe/personal/angular-day-picker/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1198:9) at doNTCallback0 (node.js:430:9) at process._tickCallback (node.js:359:13)
以下是我的 tsconfig.json 文件内容:
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"mapRoot": "",
"module": "system",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": false,
"rootDir": ".",
"sourceMap": true,
"sourceRoot": "/",
"target": "es5"
},
"files": [
"typings/main.d.ts"
],
"exclude": [
"typings/browser.d.ts",
"typings/browser"
]
}
我做错了什么?我在文档中找不到添加第三方库的指南。