Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node-Webkit not working with moment.js #2075

Closed
jbescoyez opened this issue Jul 14, 2014 · 7 comments
Closed

Node-Webkit not working with moment.js #2075

jbescoyez opened this issue Jul 14, 2014 · 7 comments

Comments

@jbescoyez
Copy link

This bug is super easy to reproduce:
package.json

{
  "name": "nw-demo",
  "main": "index.html"
}

index.html

<html>
<head>
<title>Hello World!</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

Launch nw (tested with 0.9.2 an 0.10.0). Open console.

$ moment
=> ReferenceError: moment is not defined

Launch browser, open index.html

$ moment
=> function (b,d,e,f){var g;return"boolean"==typeof e&&(f=e,e=a),g={},g._isAMomentObject=!0,g._i=b,g._f=d,g._l=e,g._strict=f,g._isUTC=!1,g._pf=c(),db(g)}

No idea why moment is not defined in node-webkit since it is in other browsers.

Cheers

@Mithgol
Copy link
Contributor

Mithgol commented Jul 14, 2014

@jbescoyez

No idea why moment is not defined in node-webkit since it is in other browsers.

Because it detects that Node.js engine is present and thus it decides not to create a global.

To work around this decision, install Moment.js as an npm module (npm install moment in the console and also append to the dependencies' section in your package.json), then var moment = require('moment') and use it.

An added bonus is that a local file works faster than a remote server (cdnjs.cloudflare.com).

@jbescoyez
Copy link
Author

Crystal clear. Thanks!

@thoughtpalette
Copy link

Thanks for this!

@Bastian82
Copy link

Ohh, i faced this issue by myself, and i lost a day to sort it out by myself :) Anyway as was mentioned it works pefectly well as in node context. cheers.

@boiawang
Copy link

boiawang commented Jul 3, 2015

moment = global.moment

@cybercoder
Copy link

I'm using electron to create a desktop app with angular, There's no problem when i use gulp-webserver in develop time, but when i need to test in electron prebuilt environment then i see this error. I can fix in electron env with using require npm package but how can fix in both?

@Mithgol
Copy link
Contributor

Mithgol commented Oct 24, 2016

@cybercoder You should ask that question in an Electron-related issue (this one is not: this one is NW.js-related) because there you'll have more developers with Electron-related experience listening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants