title: Nodejs crypto module does not work with typescript
body: <p>I am trying to implement encryption into my project using vuejs and typescript. I successfully implemented it in the .vue file, but when I try to write the encryption into a typescript class, the mocha test runs it, but when I try to compile and open it in the browser i get a javascript error in the console: </p>
  
  <pre><code>app.js:128620 Uncaught ReferenceError: require is not defined
  at Object.crypto (app.js:128620)
  at __webpack_require__ (app.js:20)
  at Object../resources/ts/Classes/Model/Crypter.ts (app.js:125233)
  at __webpack_require__ (app.js:20)
  at Object../resources/ts/Controller/AuthController.ts (app.js:125924)
  at __webpack_require__ (app.js:20)
  at Object../node_modules/babel-loader/lib/index.js?!./node_modules/babel- 
  loader/lib/index.js!./node_modules/vue- 
  loader/lib/index.js?!./resources/js/Components/Includes/Login.vue? 
  vue&amp;type=script&amp;lang=js&amp; (app.js:3308)
  at __webpack_require__ (app.js:20)
  at Module../resources/js/Components/Includes/Login.vue? 
  vue&amp;type=script&amp;lang=js&amp; (app.js:124322)
  at __webpack_require__ (app.js:20)
  </code></pre>
  
  <p>The marked line in the app.js is:</p>
  
  <pre><code>module.exports = require("crypto");
  </code></pre>
  
  <p>I already tried different importing 'strategies' in the typescript file like: </p>
  
  <pre><code>import * as crypto from "crypto";
  import crypto from "crypto";
  var crypto = require("crypto");
  </code></pre>
  
  <p>And also adding this in the webpack.mix.js</p>
  
  <pre><code>"node": {
          fs: "empty",
          crypto: true,
          http: true,
          https: true,
          os: true,
          vm: true,
          stream: true,
          path: true
      },
  </code></pre>
  
  <p>but it didn't work.</p>
  
  <p>The Crypter.ts</p>
  
  <pre><code>import crypto from "crypto";
  
  export default class Crypter {
  
      public constructor() {
      }
  
      public static publicEncrypt(data: JSON, publicKey: string): string{
          let dataStr = JSON.stringify(data);
          let dataB64 = Buffer.from(dataStr).toString("base64");
          var buffer = Buffer.from(dataB64);
          return crypto.publicEncrypt(publicKey, buffer).toString("base64"); 
      }
  }
  </code></pre>
  
  <p>The tsconfig.json</p>
  
  <pre><code>    "compilerOptions": {
          "allowUnreachableCode": false,
          "allowUnusedLabels": true,
          "alwaysStrict": true,
          "charset": "utf8",
          "declaration": true,
          "declarationDir": "resources/ts/lib/types",
          "declarationMap": true,
          "esModuleInterop": true,
          "experimentalDecorators": true,
          "importHelpers": true,
          "lib": ["ES5", "ES6", "DOM", "DOM.Iterable", "ScriptHost"],
          "locale": "en",
          "module": "commonjs",
          "moduleResolution": "node",
          "noFallthroughCasesInSwitch": true,
          "noImplicitAny": true,
          "noImplicitReturns": true,
          "noImplicitThis": true,
          "noImplicitUseStrict": false,
          "noUnusedParameters": true,
          "outDir": "public/js",
          "baseUrl": "resources/",
          "paths": {
              "Base/*":           [ "ts/*" ],
              "@js/*":            [ "js/*" ],
              "@ts/*":            [ "ts/*" ],
              "Component/*":      [ "ts/Components/*" ],
              "Interface/*":      [ "ts/Interfaces/*" ],
              "Model/*":          [ "ts/Model/*" ],
              "Controller/*":     [ "ts/Controller/*" ],
              "Helper/*":         [ "ts/Helper/*" ]
          },
          "pretty": true,
          "sourceMap": true,
          "target": "ES5",
          "typeRoots": [
              "node_modules/@types"
          ],
          "downlevelIteration": true
      },
      "include": [
          "resources/ts/**/*"
      ],
      "exclude": [
          "node_modules",
          "**/*.spec.ts"
      ],
      "files": [
          "./node_modules/@types/node/index.d.ts"
        ]
  }
  </code></pre>
  
  <p>I expect the error to be resulting from wrong compiling or other misconfigurations.</p>