将我的项目更新为Justin DuJardin's ng2-material版本0.3.8
(基于Angular 2.0.0-beta.14
)后,无法编译并出现以下错误:
Using tsc v1.8.0
ng2-material/core/util/viewport.ts(62,12): error TS2304: Cannot find name 'process'.
ng2-material/webpack_all.ts(1,1): error TS2304: Cannot find name 'module'.
ng2-material/webpack_all.ts(1,18): error TS2304: Cannot find name 'require'.
ng2-material/webpack_all.ts(2,1): error TS2304: Cannot find name 'require'.
ng2-material/webpack_all.ts(3,1): error TS2304: Cannot find name 'require'.
ng2-material/webpack_styles.ts(1,1): error TS2304: Cannot find name 'require'.
ng2-material/webpack_styles.ts(2,1): error TS2304: Cannot find name 'require'.
>> 7 non-emit-preventing type warnings
>> Error: tsc return code: 2
Warning: Task "ts:source" failed. Use --force to continue.
安装打字不能解决编译问题:
npm install typings --save-dev --global
typings install --save --ambient
如同对类似SO问题的几个答案(例如typescript getting error TS2304: cannot find name ' require'和TypeScript and ng2 rc.1 getting Error:(20, 15) TS2304: Cannot find name 'module'中所述,而不是安抚TS编译器,我宁愿找到潜在的问题并获得真正的解决方案。 ,如果有的话。
我的TS配置如下:
tsd.json
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"node/node.d.ts": {
"commit": "e0abafb1a6ff652f7ff967120e312d5c1916eaef"
},
"requirejs/require.d.ts": {
"commit": "e0abafb1a6ff652f7ff967120e312d5c1916eaef"
},
"jasmine/jasmine.d.ts": {
"commit": "e0abafb1a6ff652f7ff967120e312d5c1916eaef"
}
}
}
tsconfig.json
"files": [
"node_modules/angular2/typings/browser.d.ts",
"dist/ng2-material.d.ts",
"ng2-material/all.ts",
"ng2-material/components/backdrop/backdrop.ts",
"ng2-material/components/button/button.ts",
...
任何想法如何找到问题的根本原因并解决它?
答案 0 :(得分:1)
可悲的是,唯一的解决方案"我找到了前瞻性宣言:
declare function require(path: string) : any;
我添加到我的应用程序bootstrapping TS文件。