How to use ES6 modules from dev tools console

As far as I understand it, if I create an ES6 module, I can only import it from code that is itself a module. This means non-module code, i.e. inline Javascript, or the Chrome dev tools console can never access code that is in a module.

Is that true? Is there any way around this because it seems like a fairly extreme limitation.

24 thoughts on “How to use ES6 modules from dev tools console”

  1. You can register the function or variable in the global namespace with a line like window.myFunction = myFunction or window.myVariable = myVariable. You can do this in the module where myFunction or myVariable are declared or do it in a separate module where they have been imported.

    Once you’ve done this, you will be able to use myFunction and myVariable from the Chrome DevTools console.

    For example:

    import myModule from '/path/to/module.js';
    window.myModule = myModule;
    
    // in the console:
    myModule.foo();
    

    (Credit to @Evert for providing this solution in a comment, albeit in a rather roundabout way that took me a while to figure out.)

    Reply
  2. You can only import a module from other modules, because import is a modules feature.

    How did you ‘import’ before ES6 modules? You didn’t, because it didn’t exist. You can actually interact with an E6 Module the same was as you used interact between two independent non-module scripts.

    Reply
  3. this worked for me in node.js 12.12.0 using typescript:

    in my main.ts I import wtfnode and set it on the global namesapace:

    import * as wtf from 'wtfnode';
    (global as any).wtfm = wtf;
    

    in the Debugger console, I can now access wtfm:

    wtfm.init();
    wtfm.dump();
    
    Reply
  4. You can call functions contained in Javascript modules from the Chrome developer console using import, as in @Kin’s answer.

    If you get error "TypeError: Failed to resolve module specifier", try using the full URL for the module file. For example, on Windows 10 with IIS running locally, and Chrome 87, this works for me:

    // Call doSomething(), an exported function in module file mymodule.js
    import('http://localhost/mysite/myfolder/mymodule.js').then((m) => { m.doSomething(); });
    
    Reply
  5. Hold and drag the module file into the chrome dev console.
    Be sure to drag it to the input line section (after >) of the console.

    (This works on my Chrome 78 under Windows 10.)

    Reply
  6. There is a way to use the Chrome Dev Tools with ES6 modules, if you use VSCode and the Javascript Debugger for Chrome. I had some trouble to get it to work, but it was worth it.
    https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome

    The VSCode debugger launches a new chrome window which is connected to the VSCode debugger. You can also use Chrome Dev Tools (F12) in this window as usual. It works with ES6 modules and you can set breakpoints, use the console, inspect variables, etc…


    In case you have trouble to set up the debugger, this is how it worked for me:

    • Go to the VSCode Debug Window (CTRL+SHIFT+D) -> select Add Configuration from dropdown -> Select Chrome Launch or Chrome Launch Legacy to change "launch.json"

    my launch.json:

    {
      "name": "Launch Chrome Legacy",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:5000/auth/login",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true
    },
    {
      "name": "Launch Chrome",
      "request": "launch",
      "type": "pwa-chrome",
      "url": "http://localhost:5000/auth/login",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true
    },
    

    The key was to use "sourceMaps": true and "url": "http://localhost:5000/auth/login" instead of http://localhost:5000/blog", which is the page I actually want to debug. However, when the Debugger opens the new chrome window, my page was redirected to /auth/login, so I had to use this url.

    • You can try to disable the Preview Version of the new debugger and use the Legacy version instead:
      Turn off Debug › JavaScript: Use Preview in the VSCode settings.
    • Then Run Launch Chrome Legacy from the Debug Window in VSCode
    • To set breakpoints in VSCode, open the javascript module from Loaded Scripts
    Reply
  7. En İyi Takipçi Sitesi Hizmetleri Takip2018
    İnternetin kişilerin hayatına girmesinden bir
    süre sonra kişilerin farklı şekillerde kullanımlarına uygun olabilecek platformlar oluşturulmuştur ve bu platformlarda da kişilerin amaçlarını yerine getirilebilmesi için takipçi sayılarını
    arttırmaları ifade edilmektedir.
    Bu anlamda ise kişilere en iyi takipçi sitesi yardımcı olmaktadır.

    Bilinen bu siteler kişilere en kaliteli hizmeti vermeye çalışmaktadırlar.

    Söz konusu olan sitenin vermiş oldukları hizmetlerin arasında güvenilir olmaları yer almaktadır.

    Yani kişilerin yapacakları ödemeleri ve alacakları hizmetleri söylenildiği ve olması gerektiği
    gibi yapmaktadırlar.
    Güvenilirlik aramada en önemli sebeplerden bir tanesi de ödemelerin online ödeme şeklinde olmasıdır.

    Bunun yanında ise bu sitenin kişilerle iletişim halinde
    oldukları da söylenilebilmektedir. Yani kişilere istedikleri vakit iletişime geçebilmektedirler.

    http://www.takip2018.com

    Reply
  8. individual level bias positive adjectives starting with v to describe a person , positive words during pandemic. positive affirmations on spotify order lyrica lyrica 150 mg , friends xmas shirt community college application deadline fall 2021 positive quotes under pressure , community acquired pneumonia wikem positive affirmations youtube? positive and negative drawing planning process business, positive and negative of globalization community first credit union ukiah california.
    community unrest synonym , community first credit union hours today community bible church stockbridge ga positive pregnancy test spotting.

    Reply
  9. radeon software adrenalin 2020 edition 20.2.2 drawing program website to buy autocad lt voltcraft dso 2020 software download. new software 2020 free free office software kingsoft engeeeneringu#$sssaunnplus , office like software for mac. 2020 software engineer jobs, dreammax b9s2x software download 2020 sketchup 2020 software free download office software protection platform service cannot be found. radeon software adrenalin 2020 windows 8.1 software testing blogs 2020, essential software for pc 2020.

    Reply

Leave a Comment