Nw.js: Cannot run angular2 rx.1 quickstart

Created on 11 May 2016  路  11Comments  路  Source: nwjs/nw.js

I have been using angular2 beta to develop nw.js app, and all good so far. But I want to update angular 2 beta to rc when it released, following quickstart https://angular.io/docs/ts/latest/quickstart.html.
I got the following error:

index.html:16 Error: ReferenceError: System is not defined
        at chrome-extension://elpbigndcnondmndigpmmkhgokceoolf/app/main.js:10:4
        at Object.exports.runInThisContext (vm.js:54:17)
    Evaluating chrome-extension://elpbigndcnondmndigpmmkhgokceoolf/app/main.js
    Error loading chrome-extension://elpbigndcnondmndigpmmkhgokceoolf/app/main.js

I tried all versions from 0.13.0 to 0.15.0, no one works. Thanks

Most helpful comment

I've fixed it by downgrading systemjs to 0.19.25 from 0.19.27. It's just a workaround tho, I hope it would help you.

All 11 comments

+1 same issue here

Same for me with Aurelia.io

I didn't follow the step by step in the quick start guide, but the live sample app works for me.

Could you please upload your sample app so I can reproduce it?

I've fixed it by downgrading systemjs to 0.19.25 from 0.19.27. It's just a workaround tho, I hope it would help you.

The issue here is that require('vm').runInThisContext('console.log(x)') in nwjs does not provide implicit access to globals set as global.x = 'x', while this works in Node and Electron. I'll see if I can add a workaround in SystemJS to fall back to eval in nwjs.

@guybedford thanks for the information. Will look into it.

The reason is that the Node context is independent and shared between DOM windows in NW.js by default.

If the implicit access to globals in DOM context is expected, please consider using the "mixed context" mode, see http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/

@rogerwang thanks for the update! I'm still not sure I follow why the shared context means not having the use of implicit globals (if that is the right term here?). For example how does access to eg encodeURI work out correctly in nwjs?

@guybedford By default Node and DOM lives in different JS contexts, like 2 different DOM windows. So in Node context, when you refer to 'x', it's not the 'x' in the context of the visible window.

I got it to work by calling nw . --mixed-context however, it isn't clear for me from the docs the real difference...

@rogerwang is there anyway to get a handle to the context itself to allow require('vm').runInContext to work as expected? The benefit of vm over eval would be SystemJS source maps support in nwjs.

Was this page helpful?
0 / 5 - 0 ratings