question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add build for <script type="module">

See original GitHub issue

I’m currently trying to use import 'object-hash/dist/object_hash.js'; to pull objectHash into my project. Unfortunately, it throws the following error:

err

I created a jsfiddle that shows the problem.

At a minimum, it would be ideal to resolve the current build issue. In the future, it would be really helpful if you could support the .mjs extension in your build, such as:

https://github.com/pladaria/reconnecting-websocket/blob/master/rollup.config.js#L22

Thanks for your help.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:10

github_iconTop GitHub Comments

8reactions
cait08commented, Aug 7, 2019

Experiencing the same thing after upgrading my site to Angular 8 (which uses script type="module"). It’s a couple months later- is there a fork anyone knows about that supports this?

7reactions
flyweightcommented, Oct 15, 2018

The problem is currently related to browserify and the node crypto lib. On 1108, r = this and this = window within this context. Unfortunately when using <script type="module">, using this within its context is undefined.

crypto

Attached is the non-minified code:

(function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,__filename,__dirname){                                               
// Original code adapted from Robert Kieffer.                                                                                                         
// details at https://github.com/broofa/node-uuid                                                                                                     
(function() {                                                                                                                                         
  var _global = this;                                                                                                                                 
                                                                                                                                                      
  var mathRNG, whatwgRNG;                                                                                                                             
                                                                                                                                                      
  // NOTE: Math.random() does not guarantee "cryptographic quality"                                                                                   
  mathRNG = function(size) {                                                                                                                          
    var bytes = new Array(size);                                                                                                                      
    var r;                                                                                                                                            
                                                                                                                                                      
    for (var i = 0, r; i < size; i++) {                                                                                                               
      if ((i & 0x03) == 0) r = Math.random() * 0x100000000;                                                                                           
      bytes[i] = r >>> ((i & 0x03) << 3) & 0xff;                                                                                                      
    }                                                                                                                                                 
                                                                                                                                                      
    return bytes;                                                                                                                                     
  }                                                                                                                                                   
                                                                                                                                                      
  if (_global.crypto && crypto.getRandomValues) {                                                                                                     
    whatwgRNG = function(size) {                                                                                                                      
      var bytes = new Uint8Array(size);                                                                                                               
      crypto.getRandomValues(bytes);                                                                                                                  
      return bytes;                                                                                                                                   
    }                                                                                                                                                 
  }                                                                                                                                                   
                                                                                                                                                      
  module.exports = whatwgRNG || mathRNG;                                                                                                              
                                                                                                                                                      
}())  
Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
Modules, introduction
Build tools do the following: Take a “main” module, the one intended to be put in <script type="module"> in HTML.
Read more >
How to use code from script with type=module [duplicate]
If I get rid of type=module (and import/export by putting the showMessage function right in showImport.js ) everything works, but the whole ...
Read more >
How to add a js script as type="module" - Drupal Answers
Yes, it is possible, with the attributes property. my-library: version: 1.x js: js/App.js: { attributes: { type: module } }. See Adding ......
Read more >
TypeScript and <script type="module"></script> #13422
A first implementation of <script type="module"><script> just landed in ... If I'm right, is it possible to add an option to force path ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found