【发布时间】:2016-06-03 04:21:00
【问题描述】:
我正在尝试在 Angular2 项目 (RC.0) 中使用来自 distinctlyTyped 的 typescript tsd,但似乎无法正确加载全局依赖项:
typings install --save dt~hellojs --global --save
npm install --save hellojs
我有这样的配置:
typings.json:
"globalDependencies": {
"hellojs": "registry:dt/hellojs#0.2.3+20160423145325"
}
angular.cli.build.js:
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)',
'angular2-moment/**/*.+(js|js.map)',
'moment/**/*.+(js|js.map)',
'hellojs/**/*.+(js|js.map)'
]
});
};
系统配置.ts
/** Map relative paths to URLs. */
const map: any = {
'moment': 'vendor/moment',
'angular2-moment': 'vendor/angular2-moment',
'hellojs': 'vendor/hellojs/dist'
};
/** User packages configuration. */
const packages: any = {
'moment': { main: 'moment.js', defaultExtension: 'js' },
'angular2-moment': { main: 'index.js', defaultExtension: 'js' },
'hellojs': { main: 'hello.all.js' }
};
但是,如果我使用角度模块中的新依赖项,如下所示:
import {Component} from "@angular/core";
import {FormBuilder, ControlGroup} from "@angular/common";
import {ROUTER_DIRECTIVES, Router} from "@angular/router";
import {LoginResourceService} from "../shared/services/resources/login-resource.service";
import {AuthService} from "../shared/services/auth.service";
import {AppRoutes} from "../app-routes";
@Component({
moduleId: module.id,
selector: 'app-login',
templateUrl: 'login.component.html',
directives: [ROUTER_DIRECTIVES],
providers: [LoginResourceService],
styleUrls: ['login.component.css']
})
export class LoginComponent {
userForm:ControlGroup;
errorMessage:string;
constructor(formBuilder:FormBuilder, private _loginResource:LoginResourceService, public router:Router,
private _auth:AuthService) {
this.userForm = this.buildLoginForm(formBuilder);
}
// ...
example() {
hello.init({});
}
}
我收到编译器错误:
Error: Typescript found the following errors:
/Users/fer2d2/dev/personal/web-projects/front-joinfinity/tmp/broccoli_type_script_compiler-input_base_path-xa8whw1k.tmp/0/src/app/+login/login.component.ts (62, 5): Cannot find name 'hello'.
如果我尝试使用 import * as hello from "hellojs" 或 import hello = require("hellojs") 导入模块,失败仍然存在。
如何使用 Angular2 的 globalDependency?
提前致谢。
编辑
有:
import {hello} from "hellojs" 或
import hello from "hellojs" 或
import hello = require("hellojs")
我收到此错误:
Error: Typescript found the following errors: /Users/fer2d2/dev/personal/web-projects/front-joinfinity/tmp/broccoli_type_script_compiler-input_base_path-tKuuBwei.tmp/0/src/app/+login/login.component.ts (7, 21): Cannot find module 'hellojs'.
Typescript 或 systemjs 似乎没有正确加载 globalDependencies tsd。
【问题讨论】:
-
试试:
import {hello} from "hellojs" -
和:
import hello from "hellojs" -
import hello = require("hellojs")的错误是什么? -
嗨@2426021684。与:
import {hello} from "hellojs"和import hello from "hellojs"和import hello = require("hellojs")我收到此错误:Error: Typescript found the following errors: /Users/fer2d2/dev/personal/web-projects/front-joinfinity/tmp/broccoli_type_script_compiler-input_base_path-tKuuBwei.tmp/0/src/app/+login/login.component.ts (7, 21): Cannot find module 'hellojs'.。
标签: typescript angular