PatrickJS / es7-reflect-metadata

Webpack and Universal support for reflect-metadata refactored by @gdi2290
Apache License 2.0
14 stars 2 forks source link

crypto not found #3

Open jkyoutsey opened 8 years ago

jkyoutsey commented 8 years ago

I'm getting two errors in my browser console (Chrome latest). See end of message for call stacks. My webpack build succedes, but the browser won't finish loading the page due to the errors. My package.json specifies: "es7-reflect-metadata": "^1.5.5",

Uncaught TypeError: crypto.randomBytes is not a functiongenRandomBytes @ gen-randombytes.ts:5createUUID @ create-uuid.ts:5createUniqueKey @ create-unique-key.ts:11(anonymous function) @ weakmap.ts:5__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ metadata.ts:1__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ reflect-metadata.ts:22__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ browser.ts:1__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ polyfills.ts:18__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ bootstrap ce8ea336ef6e370d804f:93(anonymous function) @ bootstrap ce8ea336ef6e370d804f:93 decorators.ts:242Uncaught reflect-metadata shim is required when using class decorators(anonymous function) @ decorators.ts:242__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ decorators.ts:9__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ di.ts:18__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ di.ts:2__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ metadata.ts:6__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ core.ts:6__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ main.ts:4__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50webpackJsonpCallback @ bootstrap ce8ea336ef6e370d804f:21(anonymous function) @ main.bundle.js:1

And

Uncaught reflect-metadata shim is required when using class decorators(anonymous function) @ decorators.ts:242__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ decorators.ts:9__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ di.ts:18__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ di.ts:2__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ metadata.ts:6__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ core.ts:6__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50(anonymous function) @ main.ts:4__webpack_require__ @ bootstrap ce8ea336ef6e370d804f:50webpackJsonpCallback @ bootstrap ce8ea336ef6e370d804f:21(anonymous function) @ main.bundle.js:1

sasidhar commented 8 years ago

Me too facing same issue when used with 1.6.0

I am using Angular2-webpack-starter with beta 6

jkyoutsey commented 8 years ago

@sasidhar I tried going back through several versions with no change to behavior. I'm on ng2 beta 7.

sasidhar commented 8 years ago

@jkyoutsey Did you try with es7-reflect-metadata - version 1.5.5?

If you use ^1.5.5, as new version 1.6.0 is available, it will install that.

Can you try removing the caret (^) and try? For me it fixed.

jkyoutsey commented 8 years ago

@sasidhar THANK YOU! I had done that, but probably missed an npm run clean:build and it didn't revert the version that was there! That indeed did fix it for me.

Confirms that there is an issue with 1.6.0.

wtfiwtz commented 8 years ago

I've finally got angular2 beta 15 running with both Webpack and System.js (... this has taken a while!)

There are issues with es7-reflect-metadata version 1.5.5 as well... Chrome Canary 49.0.2623.110 throws up errors to do with the strict Map.length and Set.length being read-only (see https://github.com/gdi2290/es7-reflect-metadata/commit/729120155a798c49a7f07efcbc064b003aec5572).

In src/helper/create-uuid.ts you can fix the crypto issue by replacing:

import {genRandomBytes} from "./gen-randombytes"; with this: import {genRandomBytes} from "./gen-randombytes.browser";

I think crypto is part of the Node.js API is thus won't work with Typescript / ts-loader, especially on webpack.

Now my head hurts...

jhhoff02 commented 8 years ago

+1 I was getting crypto not found error for version 1.6.0... switching to 1.5.5 got rid of the error. Cheers.

nikolasleblanc commented 8 years ago

@gdi2290 can we expect an update on this? Or is this expected behaviour? Downgrading always seems like an awkward solution.