Typescript在此导入中找不到模块import ga from 'googleAnalytics';
SystemJS知道在哪里可以找到该模块,因为它已经像这样预先映射了:
map: {
'@angular': 'node_modules/@angular',
'rxjs': 'node_modules/rxjs',
'underscore': 'node_modules/underscore/underscore-min.js',
'googleAnalytics': '//www.google-analytics.com/analytics.js'
},
如何提供与的相似映射tsc
?
另一个问题似乎指向一个正确的方向:如何避免在Angular 2中使用相对较长的相对路径进行导入?
Typescript 2.0似乎支持的paths
配置tsconfig.json
。有没有办法下载Typescript 2.0?我可以path
像使用SystemJS一样为配置提供一个http网址(//www.google-analytics.com/analytics.js)吗?如果无法下载Typescript 2.0,如何在当前版本中实现所需的功能?
编辑
我得到的具体错误是:“找不到模块'ga'”。
这是我的tsconfig.json
:
{
"compilerOptions": {
"rootDir": "./",
"target": "es5",
"module": "system",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true
},
"exclude": [
"node_modules",
"front-end/node_modules",
"typings/main",
"typings/main.d.ts"
]
}
我猜您了解,在进行TypeScript编译的情况下,transpiler会查找明确的类型文件。他需要知道外部模块的类型定义。我假设您拥有有效的nodejs模块解析(您拥有),并且使用了非相对路径(您确实拥有),则必须将其添加到项目的node_modules目录中(也许已经有了一个),并在此目录中添加googleAnalytics.d.ts文件,或者您可以创建node_modules / googleAnalytics目录,然后在其中添加index.d.ts。可以从DefintelyTyped存储库下载Google Analytics(分析)的定义类型
有关模块分辨率的更多信息,请点击此处
编辑:根据您的评论,也许您将不得不将模块导出添加到Google定义文件
declare module 'googleAnalytics' {
export = UniversalAnalytics;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句