0

Doing it this way:

const _ = await import('https://unpkg.com/lodash')

gives me a strange object with single Symbol(Symbol.toStringTag) prop valued "Module".

Note 1: I'm aware of the trick

import _ from 'lodash'
window._ = _

in your code, please give your answer only if the import works directly from browser's dev tools console.

Note 2: I'm also aware that this question has been asked many times. I read through all the answers, they either do not work nowadays or are inapplicable because of Note 1. So I decided to ask it again.

repka
  • 2,909
  • 23
  • 26

1 Answers1

1

This is a lodash specific thing I recon as it uses an IIFE

await import("https://unpkg.com/lodash");
console.log(_, window._);
Vivick
  • 3,434
  • 2
  • 12
  • 25
  • 1
    Thank you. I'm marking this as answer because after more research I reached the similar conclusion that the module export is not how browsers handle scripts and hence your code is somewhat analogous to **document.body.appendChild(Object.assign(document.createElement("script"), {type:'text/javascript', src:'https://unpkg.com/lodash'}))** which just loads the script and runs it. And whatever globals that script adds is how you use it. At this point I assume there's no way to load the script as a module and get either its named or default exports. If there is a way please let me know! – repka Aug 17 '23 at 20:51