0

After updating my project to Justin DuJardin's ng2-material version 0.3.8 (based on Angular 2.0.0-beta.14), it fails to compile with the following errors:

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.

Installing typings does not solve the compilation problem:

npm install typings --save-dev --global
typings install --save --ambient

Instead of appeasing the TS compiler, as noted in several answers to similar SO questions, e.g., typescript getting error TS2304: cannot find name ' require' and TypeScript and ng2 rc.1 getting Error:(20, 15) TS2304: Cannot find name 'module', I'd prefer to find the underlying problem and get a real fix for that, if there is one.

My TS configuration is as follows:

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",
    ...

Any ideas how I can find the root cause of this issue and solve it?

Daniel
  • 3,541
  • 3
  • 33
  • 46
Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119

1 Answers1

1

Sadly, the only "solution" I found is the forward-declaration work-around:

declare function require(path: string) : any;

which I added to my application bootstrapping TS file.

Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119