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

Can't resolve all parameters for services or components when using NW js with ANGULAR 6 #6804

Closed
ef32 opened this issue Sep 18, 2018 · 17 comments

Comments

@ef32
Copy link

ef32 commented Sep 18, 2018

======== TEMPLATE BUG FORM ========

NWJS Version : Latest (0.33.3)
Operating System : Windows

Expected behavior

It shouldnt matter if angular has upgraded to 6. It should load Application

Actual Behaviour

Load Angular application 6 on web , it works but if you attempt to load using nwjs latest, for all classes error is Can't resolve all parameters for 'A component' or 'A service'. Angular 5 works without an issue, i upgraded the same project to angular 6 , works on web but not on nw js.

@ef32
Copy link
Author

ef32 commented Sep 18, 2018

@rogerwang is NWjs compatible with ng 6 so we know what next? Does it require polyfill

@ef32
Copy link
Author

ef32 commented Sep 19, 2018

@rogerwang please can you respond to this, my company strongly depends on NWJS and we need this resolved asap . If there is no answer , please inform so we can roll back to angular 5

@ef32
Copy link
Author

ef32 commented Sep 20, 2018

@rogerwang Angular 6 applies a polyfill of corejs/es7/ reflect. Is that not compatible with NWJS anymore?

@rogerwang
Copy link
Member

rogerwang commented Sep 20, 2018 via email

@ef32
Copy link
Author

ef32 commented Sep 20, 2018

@rogerwang i have created a repository with a sample application in angular 6 to reproduce the problem as our original app is large. the kiosk configuration is there too . If you go into my profile you will find the repository called sample-nwjs. thank you for your response, my stakeholders are seriously on my case and we are working tirelessly as i respond to you , for a workaround

@rogerwang
Copy link
Member

I have downloaded your sample, but both running ng serve and ng build in Turf give the following error:

Could not find module "@angular-devkit/build-angular" from "C:\\tests\\sample-nwjs\\sample\\Turf".
Error: Could not find module "@angular-devkit/build-angular" from "C:\\tests\\sample-nwjs\\sample\\Turf".
    at Object.resolve (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\core\node\resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\architect\src\architect.js:132:40)
    at Observable._trySubscribe (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:43:25)
    at Observable.subscribe (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:29:22)
    at DoOperator.call (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\operators\tap.js:29:23)
    at Observable.subscribe (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:24:22)
    at C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\util\subscribeTo.js:22:31
    at Object.subscribeToResult (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\util\subscribeToResult.js:7:45)
    at MergeMapSubscriber._innerSub (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:75:38)
    at MergeMapSubscriber._tryNext (C:\Users\roger\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:72:14)

@ef32
Copy link
Author

ef32 commented Sep 20, 2018

@rogerwang I just did the same and it compiled . see shot below:

build

maybe you should run npm install first. If you look up the package.json file its there.

@rogerwang
Copy link
Member

I can reproduce your issue now. But it runs well if I run nw.exe --url=http://localhost:4200. So I guess the root cause seems to be that Angular defines require() somehow and it conflicts with the require() defined in NW to load Node modules. See more at https://github.com/nwjs/nw.js/wiki/faq-name-conflict

@Zenohactagamat
Copy link

If this can help I had a similar problem this morning :

  • Angular CLI 6.2.3 fresh install
  • Nw.js 0.32.4 fresh install
  • ng new my-app
  • ng serve

My package.json at the moment :

"main": "http://localhost:4200",
"node-remote" : "http://localhost:4200",
"name": "my-app",
"description": "My app",
"version": "0.1.0",
"window": {
"title": "node-webkit demo",
"icon": "favicon.ico",
"frame": false,
"position": null,
"width": 2960,
"height": 1050,
"min_width": 2960,
"min_height": 1050,
"always_on_top": false
},
...

I fixed my problem by removing the node-remote option. (fortunately I don't need nodejs stuff for my project)

@ef32
Copy link
Author

ef32 commented Sep 20, 2018

If this can help I had a similar problem this morning :

  • Angular CLI 6.2.3 fresh install
  • Nw.js 0.32.4 fresh install
  • ng new my-app
  • ng serve

My package.json at the moment :

"main": "http://localhost:4200",
"node-remote" : "http://localhost:4200",
"name": "my-app",
"description": "My app",
"version": "0.1.0",
"window": {
"title": "node-webkit demo",
"icon": "favicon.ico",
"frame": false,
"position": null,
"width": 2960,
"height": 1050,
"min_width": 2960,
"min_height": 1050,
"always_on_top": false
},
...

I fixed my problem by removing the node-remote option. (fortunately I don't need nodejs stuff for my project)

@Zenohactagamat unfortunately we need nodejs modules in our project. @rogerwang i will look at thelink provided and get back to you now if that can solve our issues.

@ef32
Copy link
Author

ef32 commented Sep 20, 2018

@rogerwang when we removed node-remote option, it worked but we lost access to the nodejs functionalities, including nw object. I even added the script as specified as alternative in the link, with node-remote specified and it did not work. any suggestions please?

@rogerwang
Copy link
Member

My suggestion is resolving the name conflict. See more information in the link.

@ef32
Copy link
Author

ef32 commented Sep 20, 2018

@rogerwang is there an alternative to specifying node-remote ? maybe that could solve the issue at hand

@ef32
Copy link
Author

ef32 commented Sep 20, 2018

For any one who uses NWJS with Angular 6 and requires Node capabilities like i do, i was able to rectify this after @rogerwang referred me to this link. However, the suggestions there most certainly may not work if Node functionality is required along side angular; the conflict in both Node REQUIRE definitions (Angular 6 and NWJS) occurs in the angular compiler prior to loading the app so adding the script in your index.html file or polyfill.ts ordinarily will not rectify the issue. To solve this, in your nw manifest, do not remove the node-remote field or nodejs flag, add a new field bg-script and pass a js file with the workaround expressions specified in the link above. In your Angular app, re assign the require function in your nw object. That solves it. See Example below

removeRequire.js

window.requireNode = window.require;
window.require = undefined;

NW package.json

{"name": "angular-app",
  "version": "0.0.0",
  "main": "http://localhost:4200/",
  "node-remote": "http://localhost:4200",
  "bg-script": "removeRequire.js",
  "window": {
    "toolbar": false,
    "title": "App",
    "width": 550,
    "height": 870
  },
  "scripts": {
    "start": "nw ."
  }
}

Angular 6 app polyfill.ts

declare var nw: any;
const isNWjsAvailable = typeof (nw) === 'object';

(function(inkioskMode: boolean) {
    if (inkioskMode) {
        nw.require = nw.global.require =  nw.global.requireNode;
        nw.global.requireNode = undefined;
    }
}(isNWjsAvailable));

Note

This is useful if you require node capabilities through the nw kiosk. If It isnt needed, just simply remove the node-remote field. Also, the script provided for the bg-script field should be in the same folder as your nw manifest. It may also not be needed if building or serving AOT.

@rogerwang thanks for pointing me in the right direction. this was one head ache 👍

@TheJaredWilcurt
Copy link
Member

TheJaredWilcurt commented Feb 24, 2019

Here is a tutorial for the latest Angular-CLI and NW.js

@kriefsacha
Copy link

Hi , how do you do to build the app when it's done ? I used nwjs-builder-phoenix but the ng serve command is not running so i have an error that localhost is not available.

@jonnathanlopes
Copy link

Aqui está um tutorial para as últimas Angular-CLI e NW.js

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