title: AngularJs ReferenceError: require is not defined
body: <p>I know there is other questions about this problem, but I've ready more than 10 answers and tried every single one and none of them worked for me.</p>
  
  <p>I'm getting this error: <code>Uncaught ReferenceError: require is not defined</code> when i try to load an external plain javascript file to encode in JWT.</p>
  
  <p>This is the file I'm trying to include with <code>require()</code>: <a href="https://github.com/hokaccha/node-jwt-simple" rel="nofollow">https://github.com/hokaccha/node-jwt-simple</a> I've download with <code>npm</code>.</p>
  
  <p>In my code I tried lots of things.</p>
  
  <ul>
  <li>Include in the <code>main.js</code> with grunt concact;</li>
  <li>Load manually inside the <code>&lt;head&gt;</code> with the <code>&lt;script src="path/to/folder"&gt;&lt;/script&gt;</code>;</li>
  <li>Install RequireJs with npm for nodeJs;</li>
  </ul>
  
  <p>With all of those attempts, I got the same errors. What am I doing wrong?</p>
  
  <p>This is the code I'm using right now:</p>
  
  <p><strong><em>index.html</em></strong></p>
  
  <pre><code>&lt;head&gt;
  &lt;script type="text/javascript" src="dist/js/angular.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="dist/js/ui-router.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="dist/js/jwt.js"&gt;&lt;/script&gt;
  [... rest of head ...]
  </code></pre>
  
  <p><strong><em>appCtrl.js</em></strong> (will concat later on the build with the rest of the app)</p>
  
  <pre><code>.controller('MainCtrl', 
      ['$rootScope', '$scope', '$state', 
      function($rootScope, $scope, $state) {
          var jwt = require('jwt');
          var payload = { foo: 'bar' };
          var secret = 'xxx';
          var token = jwt.encode(payload, secret);
          console.log(token);
  }])
  </code></pre>
  
  <p>My main objective with this is to handle the user authentication based on a JWT token. The problem right now is to encode/decode the token when the user is login in into the app.</p>
  
  <p>Even with all of these, I still get the error. Do you guys know how to fix this?</p>