Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading external library in Chrome console

I am using React and Redux. Inside my Reducer I am using lodash library.

debugger; command stops the execution

If I import lodash library

import _ from "../../node_modules/lodash";

or

import _ from "lodash";

enter image description here

It fails. It cannot import the library. There is no loading error when I run my React application. I was wondering how do you load an external library(i.e lodash) in Google Chrome console?

like image 934
learner2017 Avatar asked Oct 14 '25 18:10

learner2017


1 Answers

Use dynamic import syntax instead, and you'll get back a Promise with what you want. For example, on this page:

https://stackoverflow.com/questions/57032914/loading-external-library-in-chrome-console

using

import('../../foo')

results in

enter image description here

Assuming that on your own site, the link is proper, all you need to do is call .then on the Promise:

import("../../node_modules/lodash")
  .then((_) => {
    // do stuff with _
  });

(of course, this requires that node_modules be a subfolder of the grandparent directory of the current page)

like image 61
CertainPerformance Avatar answered Oct 17 '25 09:10

CertainPerformance