I'm using NPM for dependency management and Angular5 with TypeScript.
EDIT I haven't installed the crypto package from npm, I am referencing the node inbuilt package.
No matter what I do, the "crypto" package resolves as an empty object. I have installed the node @typings package and can see the definition for @typings definition crypto in the node_modules/@typings folder.
What I've tried:
import * as cryp from 'crypto'
declare var crypto:any
declare module crypto
var cryp = require('crypto')
I tried deleting the modules folder and reinstalling.
I tried updating everything to the most recent version.
I tried creating a new project and only using crypto with no additional dependencies. No luck.
The biggest issue here is we are trying to use libraries which depend on this 'crypto' module and they do not function without it.
What's most confusing about this is it doesn't throw any errors, and it's not coming as undefined, but an empty object. It doesn't work in the project or outside of it. And other Node JS/TS modules are working fine, it's literally (so far) just 'crypto' which is having this issue. Any guidance or thoughts here would be great.
Primarily using ng serve to run the application but tried packaging and running using node directly as well.
Per @kendor 's suggestion, I ran a tsc --traceResolution. This is the part regarding crypto. Interestingly it says "node_modules" does not exist, but it clearly does, and other packages are resolving from it correctly.
======== Resolving module 'crypto' from '[...]/src/app/app.component.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
Loading module 'crypto' from 'node_modules' folder, target file type 'TypeScript'.
Directory '[...]/src/app/node_modules' does not exist, skipping all lookups in it.
Directory '[...]/src/node_modules' does not exist, skipping all lookups in it.
File '[...]/node_modules/crypto.ts' does not exist.
File '[...]/node_modules/crypto.tsx' does not exist.
File '[...]/node_modules/crypto.d.ts' does not exist.
File '[...]/node_modules/@types/crypto.d.ts' does not exist.
Directory '[...]/node_modules' does not exist, skipping all lookups in it.
Directory '[...]node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
Loading module 'crypto' from 'node_modules' folder, target file type 'JavaScript'.
Directory '[...]/src/app/node_modules' does not exist, skipping all lookups in it.
Directory '[...]/src/node_modules' does not exist, skipping all lookups in it.
File '[...]/node_modules/crypto.js' does not exist.
File '[...]/node_modules/crypto.jsx' does not exist.
Directory '[...]/node_modules' does not exist, skipping all lookups in it.
Directory '[...]node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'crypto' was not resolved. ========