2

Hi I am trying to compile angular2 with Webpack, all seems to work fine a part that I get this error

nodecrm/node_modules/reflect-metadata/Reflect.ts
(1406,33): error TS2304: Cannot find name 'msCrypto'. 

I was following angular website guid https://angular.io/docs/ts/latest/guide/webpack.html is there something that I am missing? My tsconfig.json file looks like:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
    "exclude": [
            "node_modules",
            "typings/browser",
            "typings/browser.d.ts"
    ],
    "compileOnSave": true,
    "buildOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    }
}

Thanks for any suggestions...

2
  • I have the exact same error on an old project built on angular2 and webpack. Did you find a solution for this? Commented Jan 16, 2019 at 20:29
  • I have the exact same error on an old project built on angular2 and webpack. Did you find a solution for this? Commented Feb 7, 2020 at 21:27

3 Answers 3

1

For me it was caused by the angular2-universal-polyfills package that contains an old version of the reflect-metadata package. I've fixed it by downloading the actual reflect-metadata with npm:

npm install reflect-metadata

Then copied the node_modules\reflect-metadata folder into the node_modules\angular2-universal-polyfills\node_modules folder, rewriting the old one there.

Hope this helps someone facing this issue. I was working on an old project with angular2.4.5 and webpack.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me for development, but when I publish in Visual Studio, it rebuilds the resources, so the publication fails. I don't know how to get around this.
0

Latest tsconfig.json from webpack introduction article looks like below-

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}

Try changing to this. See if this helps.

4 Comments

Nope this doesn't help, I've tried almost all different combinations of the tsconfig, but no success. Also reinstalled the angular and that problematic lib reflect-metadata but still no success.
Which IDE you are using? Webstorm ? If yes, then explicitly use below code- /// <reference path="../node_modules/reflect-metadata/reflect-metadata.d.ts" /> import '../node_modules/reflect-metadata/Reflect';
No it's Atom, I've tried this as well, produces even more errors. I think the problem is in typings probably there is no definition for this module msCrypto and the comillator can't recognise it. Before I had a similar error, and I had to just find the right typing with typings search [module] and then install it. but I now when I search for msCrypto there is no any record for this module.
I am able to run Angular2 RC2 webpack introduction application on my machine. My environment is - Windows7 64bit OS, VScode 1.2.1, node v4.4.5, npm v3.9.5 and chrome browser.
0

The reflect-metadata package has a dependency over crypto so install them as,

npm install reflect-metadata crypto --save

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.