Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make chrome devtools to recognise moment.js

Tags:

I am working on ionic2 project. I have just start using moment.js but I have a weird issue. I have installed in via npm: npm install moment -S.

Then I have used it in my code:

import moment from 'moment' ... let x = moment() debugger 

On the console I get this funny issue:

> x < Moment {_isAMomentObject: true, _isUTC: false, _pf: {…}, _locale: Locale, _d: Wed Jun 27 2018 12:06:23, …} > y = moment() < VM770:1 Uncaught ReferenceError: moment is not defined     at eval (eval at Phase (phase.ts:13), <anonymous>:1:1)     at new Phase (phase.ts:13)     at new Stage (stage.ts:10)     at new HomePage (home.ts:39)     at createClass (core.es5.js:10795)     at createDirectiveInstance (core.es5.js:10621)     at createViewNodes (core.es5.js:11971)     at createRootView (core.es5.js:11876)     at callWithDebugContext (core.es5.js:13007)     at Object.debugCreateRootView [as createRootView] (core.es5.js:12468) 

Why can't I work with moment within the console?

like image 995
user1692261 Avatar asked Jun 27 '18 09:06

user1692261


People also ask

How do I run JavaScript in Chrome dev tools?

Open Chrome, press Ctrl+Shift+j and it opens the JavaScript console where you can write and test your code.

How do I enable the JavaScript console in Chrome?

To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools > Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).


1 Answers

Could fetch it from browser console like this:

fetch('https://momentjs.com/downloads/moment.min.js')     .then(response => response.text())     .then(text => eval(text)) 

Then you could use it normally there

like image 78
Agustin Diez Avatar answered Oct 11 '22 21:10

Agustin Diez