Solvedangular cli ERROR in [default] Variable 'module' must be of type 'NodeModule', but here has type '{ id: string; }'.

Hi,

I have some errors with typings.d.ts when I used ng serve. How can I fix it?

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
    Mac OS X Yosemite
  2. Versions. Please run ng --version. If there's nothing outputted, please run
    in a Terminal: node --version and paste the result here:
    angular-cli: 1.0.0-beta.11-webpack.8
    node: 6.4.0
    os: darwin x64
  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.
    Migrating from angular-cli@webpack.2 to angular-cli@webpack.8. Using angular rc6.
  4. The log given by the failure. Normally this include a stack trace and some
    more information.

ERROR in [default] [..]website/src/typings.d.ts:6:12
Subsequent variable declarations must have the same type. Variable 'module' must be of type 'NodeModule', but here has type '{ id: string; }'.

ERROR in [default] [..]website/src/typings.d.ts:7:12
Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'any'.

  1. Mention any other details that might be useful.

Thanks! We'll be in touch soon.

15 Answers

✔️Accepted Answer

Although no longer a fatal error, when using the cli (rc.4 as of today) it generates a typings.d.ts file that contains

/* SystemJS module definition */
declare var module: {
  id: string;
};

This generates the warning 'Variable 'module' must be of type 'NodeModule' in IDEs WebStorm and Visual Studio Code

In node_modules/@types/node/index.d.ts (currently v6.0.66)there is already this definition

interface NodeModule {
    exports: any;
    require: NodeRequireFunction;
    id: string;
    filename: string;
    loaded: boolean;
    parent: NodeModule | null;
    children: NodeModule[];
}

declare var module: NodeModule;

which is causing the conflict as the fields in NodeModule are not optional.

So as @moxival says you can comment it out as module is already defined in node_modules/@types/node/index.d.ts
or change typings.d.ts to

/* SystemJS module definition */
declare var module: NodeModule;

Other Answers:

@Chabane do you have @types/node or lingering node folder inside node_modules/@types? You can maybe just comment out the NodeModule of the typings.d.ts

Angular CLI 1.0 updated new code and it works now:

/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
  id: string;
}

More Issues: