How do I load NPM packages in browser dev tools console?

Advertisements

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.

>Solution :

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

await import("https://unpkg.com/lodash");
console.log(_, window._);

Leave a ReplyCancel reply