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

feat(angular): v10 support #286

Merged
merged 7 commits into from
Jul 30, 2020
Merged

feat(angular): v10 support #286

merged 7 commits into from
Jul 30, 2020

Conversation

NathanWalker
Copy link
Contributor

No description provided.

@project-bot project-bot bot added this to Pull Request in CLI Team Jul 14, 2020
@cla-bot cla-bot bot added the cla: yes label Jul 14, 2020
@d-koppenhagen
Copy link
Contributor

When I run ng add @nativescript/schematics@rc --skipAutoGeneratedComponent using an Angular 10 repo, I run into the following error:

Installing packages for tooling via npm.
Installed packages for tooling via npm.
    Reading Project Settings
    Project settings:
    {
      "root": "",
      "sourceRoot": "src",
      "mainName": "main",
      "mainPath": "src/main.ts",
      "prefix": "bm",
      "tsConfig": "tsconfig.app.json",
      "entryModuleClassName": "AppModule",
      "entryModuleImportPath": "./app/app.module",
      "entryModuleName": "App",
      "entryModulePath": "src/app/app.module.ts",
      "entryComponentClassName": "AppComponent",
      "entryComponentImportPath": "./app.component",
      "entryComponentName": "App",
      "entryComponentPath": "src/app/app.component.ts",
      "indexAppRootTag": "bm-root"
    }
    Adding @nativescript/schematics to angular.json
    Adding {N} files
    Adding App_Resources
    Adding NativeScript specific exclusions to .gitignore
    Adding NativeScript run scripts to package.json
    Adding NativeScript Project ID to package.json
    Modifying web tsconfig
File tsconfig.app.json could not be parsed!

@NathanWalker
Copy link
Contributor Author

NathanWalker commented Jul 30, 2020

@nativescript/schematics ~10.0.0 has now been published alongside @nativescript/angular ~10.0.0

Here's a couple examples if starting fresh (which are already documented) but here for quick reference:

A. Starting a new Angular web project and adding {N} to it afterwards:

ng new workspace
cd workspace
ng add @nativescript/schematics --skipAutoGeneratedComponent

// start apps:
npm run ios
npm run android 

B. Starting a new Angular NativeScript shared codebase from the start:

npm i -g @nativescript/schematics
ng new -c=@nativescript/schematics workspace --shared --style=scss
cd workspace

// start apps:
npm run ios
npm run android 

If updating existing @nativescript/schematics projects:

  1. Delete webpack.config.js (the updated @nativesript/webpack dependency will regenerate a new correct one using latest webpack plugins). If you had customizations, use git change sets to compare the diff.
  2. Update package.json as follows (at least in part - can use as a guide):
"scripts": {
  "clean": "npx rimraf hooks node_modules package-lock.json platforms",
  "ng": "ng",
  "start": "ng serve",
  "build": "ng build",
  "test": "ng test",
  "lint": "ng lint",
  "e2e": "ng e2e",
  "android": "tns run android --no-hmr",
  "ios": "tns run ios --no-hmr",
  "mobile": "tns run",
  "preview": "tns preview",
  "ngcc": "ngcc --properties es2015 module main --first-only",
  "postinstall": "npm run ngcc"
},
"dependencies": {
  "@angular/animations": "~10.0.0",
  "@angular/common": "~10.0.0",
  "@angular/compiler": "~10.0.0",
  "@angular/core": "~10.0.0",
  "@angular/forms": "~10.0.0",
  "@angular/platform-browser": "~10.0.0",
  "@angular/platform-browser-dynamic": "~10.0.0",
  "@angular/router": "~10.0.0",
  "core-js": "^2.6.9",
  "@nativescript/angular": "~10.0.0",
  "@nativescript/core": "rc",
  "@nativescript/theme": "~2.2.1",
  "reflect-metadata": "~0.1.12",
  "rxjs": "~6.5.5",
  "tslib": "1.10.0",
  "zone.js": "~0.10.2"
},
"devDependencies": {
  "@angular/cli": "~10.0.0",
  "@angular/compiler-cli": "~10.0.0",
  "@angular-devkit/build-angular": "~0.1000.2",
  "@nativescript/tslint-rules": "~0.0.5",
  "@types/jasmine": "~3.5.0",
  "@types/jasminewd2": "~2.0.3",
  "@types/node": "^12.11.1",
  "codelyzer": "^5.1.2",
  "jasmine-core": "~3.5.0",
  "jasmine-spec-reporter": "~4.2.1",
  "karma": "~4.4.1",
  "karma-chrome-launcher": "~3.1.0",
  "karma-coverage-istanbul-reporter": "~2.1.0",
  "karma-jasmine": "~3.0.1",
  "karma-jasmine-html-reporter": "^1.4.2",
  "@nativescript/webpack": "~2.0.0",
  "protractor": "~5.4.3",
  "ts-node": "~8.3.0",
  "tslint": "~6.1.0",
  "typescript": "~3.9.0",
  "node-sass": "^4.7.1"
}
  1. Clean your projects with npm run clean if using the clean scripts from the example scripts above.

@NathanWalker NathanWalker merged commit 55fa354 into master Jul 30, 2020
CLI Team automation moved this from Pull Request to Done Jul 30, 2020
@NathanWalker NathanWalker deleted the feat/angular-10 branch July 30, 2020 05:09
@d-koppenhagen
Copy link
Contributor

🥳

@mahmoudajawad
Copy link

mahmoudajawad commented Jul 30, 2020

@NathanWalker, I just tried creating a new share app but web wouldn't start with the following error:

Uncaught ReferenceError: __decorate is not defined
    at Module../src/app/home/home.component.ts (home.component.ts:8)
    at __webpack_require__ (bootstrap:79)
    at Module../src/app/app.routes.ts (app.routes.ts:3)
    at __webpack_require__ (bootstrap:79)
    at Module../src/app/app-routing.module.ts (app-routing.module.ts:1)
    at __webpack_require__ (bootstrap:79)
    at Module../src/app/app.module.ts (app.module.ts:1)
    at __webpack_require__ (bootstrap:79)
    at Module../src/main.ts (main.ts:1)
    at __webpack_require__ (bootstrap:79)

I've been getting this error in rc version as well, but even after upgrading to following versions:

* tns/nsc: 6.8.0
* @nativescript/schematics: 10.0.1

I'm still getting the same error on skeleton new shared project.

UPDATE: Just to assert this again. Web wouldn't work, but mobile does work.

@mahmoudajawad
Copy link

On some trial and error I was able to get this working by changing tsconfig.json value:

"noEmitHelpers": true,

to

"noEmitHelpers": false,

then, adding the same value as true to tsconfig.tns.json.

This gets new projects to work, but upgrading current projects is not really working. I was able to make huge progress in upgrading one project following: NativeScript/nativescript-angular#2152 (comment), however, other parts are still broken. I'm trying to figure out if these are just project-specific, or more ns-ng-related issues.

@NathanWalker
Copy link
Contributor Author

@mahmoudajawad thanks for report - possible to drop a project on github where experiencing the issues - if private you can send email to support@nativescript.org and we can help take a look.

@mahmoudajawad
Copy link

@NathanWalker, appreciate your reply. I was working on this for more time and finally I figured out the specific steps to take into consideration for being able to upgrade a current project. I was testing this on a private project, but later confirmed the same steps on my repo (https://github.com/mahmoudajawad/nativescript-pokedex), which is:

  1. (-2) As outlined in your comment: feat(angular): v10 support #286 (comment)
  2. ...
  3. Remove tns-android, tns-ios from package.json to force platform modules version upgrade.
  4. npm run clean && npm run [android|ios] to remove all modules, and install new modules.
  5. Your app is upgraded now, but if coming from @nativescript/schematics corresponding to NG8, you need to do the following:
    1. Change all nativescript-angular[/*], tns-core-modules[/*] to @nativescript/angular, @nativescript/core respectively, and drop all deep imports (e.g.: nativescript-angular/*, tns-core-modules/*) and replace with top-level imports (e.g.: import { X, Y, Z } from '@nativescript/[angular|core]') only: Impossible to run ns app after migration to Angular 9 even with enableIvy = false nativescript-angular#2152 (comment)
    2. Some classes are not available anymore under the previous structure such as screen from tns-core-modules/platform (Nathan, can you confirm?) and you would need to import it as Screen from top-level @nativescript/core.
    3. Similar goes to applicationsSettings from tns-core-modules/application-settings which is now imported as ApplicationSettings from @nativescript/core.
    4. For DEVICE which used to be imported and injected as service to access Device class, it doesn't seem to be working anymore so you would need to disable this for now (Nathan, can you confirm?).
  6. It seems that tns run [android|ios] is not working anymore as it runs the app with default HMR option, for that, you either need to do tns run [android|ios] --no-hmr, or use the invoked npm cli script npm run [android|ios].
  7. There used to be a trick for HMR livesync and automatic re-routing to the same route you would have been on (https://gist.github.com/vakrilov/f6add06310ad1799c38ee14781a64ab1) and doesn't seem to work anymore.
  8. One very interesting issue I faced was the following error: com.tns.NativeScriptException: Calling js method onCreate failed followed with java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup on Android, Root should be either UIViewController or UIView on iOS. After trial and error, I found out having <page-router-outlet></page-router-outlet> alone in app.component.tns.html breaks the app and wrapping it with any layout component such as GridLayout would resolve this error.

These changes can be found on the last commit of the same project referenced earlier.

On new projects, it seems something is causing tsconfig not to be happy when creating new project with --collection option. However, creating Angular 10 project, then adding @nativescript/schematics seems to be the way to go for new projects.

That said, unit testing is still broken. I created an issue for rc version NS+NG10 (NativeScript/nativescript-angular#2201), however I'm now seeing different errors from the ones mentioned in the issue. I'll update the other issue with the new findings of release version of NS+NG10.

Moreover, you mentioned earlier that you are developing this lib (nativescript/schematics) although as a team you aren't using it. That's very great, and shows how committed towards the community you are. I'm glad I chose NativeScript and continued to do so for the past years. Really, I can't explain how appreciated I am for your efforts. For that, I would like to offer a hand that might help you building this. I might be able to help you testing this lib against current projects (I'm just beginning with nativescript/schematics after the successful project to build shared-templates-app across web and mobile), or maybe help giving some tips on using it. I'm not sure how I can help, but here it's anyway I'm offering it to you. Let me know, if I can be of help to you.

@thientm
Copy link

thientm commented Jul 31, 2020

@NathanWalker hello, i'm follow A. Starting a new Angular web project and adding {N} to it afterwards:
I have two issues:
1: when npm run android -> it will show error

ERROR in The loader "F:/webApp/src/app/auto-generated/auto-generated.component.less" didn't return a string

I must comment out in .component
//styleUrls: ['./auto-generated.component.less' => to skip this error , but it won't use style in component

2: tns preview error -> it show ngModuleDef

`LOG from device Galaxy S9: com.tns.NativeScriptException: Error calling module function
Error: Type AppRoutingModule does not have 'ngModuleDef' property.
File: (file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1682:12)

StackTrace:
ZoneAwareError(file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:1298:33)
at getNgModuleDef(file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1682:19)
at (file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1513:31)
at noSideEffects(file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1321:19)
at ����setNgModuleScope(file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1512:16)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:58:131)
at ./app/app-routing.module.tns.ts(file:///data/data/org.nativescript.preview/files/app/bundle.js:58:339)
at webpack_require(file:///data/data/org.nativescript.preview/files/app/runtime.js:817:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at ./app/app.module.tns.ts(file:///data/data/org.nativescript.preview/files/app/bundle.js:116:89) at webpack_require(file:///data/data/org.nativescript.preview/files/app/runtime.js:817:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:203:77)
at ./main.tns.ts(file:///data/data/org.nativescript.preview/files/app/bundle.js:268:30)
at webpack_require(file:///data/data/org.nativescript.preview/files/app/runtime.js:817:30)
at checkDeferredModules(file:///data/data/org.nativescript.preview/files/app/runtime.js:44:23)
at webpackJsonpCallback(file:///data/data/org.nativescript.preview/files/app/runtime.js:31:19)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:2:57)
at require(:1:266)

Error: Type AppRoutingModule does not have 'ngModuleDef' property.
at com.tns.Runtime.runModule(Native Method)
at com.tns.Runtime.runModule(Runtime.java:674)
at com.tns.Runtime.run(Runtime.java:666)
at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7145)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7095)
at android.app.ActivityThread.access$1700(ActivityThread.java:273)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2105)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8125)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)`

@mahmoudajawad
Copy link

@thientm, scss does seem to work. If it's an option to you, maybe try using it instead.

@NathanWalker
Copy link
Contributor Author

NathanWalker commented Jul 31, 2020

@mahmoudajawad just excellent 👏 - I wonder if dropping that up on a blog post would help provide more visible clarity to an upgrade? If you agree if possible to put that comment in some markdown and can send in Twitter perhaps then I can add some other details to it and can help provide better pointers to an update. We also are looking at writing an AST transformer to be used with nsc migrate which could automatically adjust projects for some of those changes. The unit testing plugin needs update for es2017 targeting and I'll look at that thanks.

@thientm we'll look at less, possible the loader needs adjustment.

@betosalvador
Copy link

Hello @NathanWalker, I'm having the same problem 'Error: Type AppRoutingModule does not have 'ngModuleDef' property.'.

I just installed:
@angular/cli@10.0.1
nativescript@6.8.0
@nativescript/schematics@10.0.1

And I run:
ng: ng new --collection=@nativescript/schematics test-my-shared-app --shared
cd test-my-shared-app
tns preview

And the message above is showed.

Must I do any kind of configuration?

thank you in advance

@mahmoudajawad
Copy link

@NathanWalker, very well. I shall format the points as a post and send it across.

@betosalvador, the thing seems to be related to using tns command. Try using npm run PLATFORM instead.

@betosalvador
Copy link

@mahmoudajawad ,
thanks, I'll try,
but in my case I'm trying to run the preview.
maybe is note the same problem, but thank you anyway

@betosalvador
Copy link

hi @mahmoudajawad

I tryed npm run preview but I got the same error.
I'll post the full error below.

If you can give me any other tip, I'll try too.

Thanks in advance:

================================

Webpack compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (android)
Start sending initial files for device %H:%M:%S (84033bdf-d3d6-43a3-9857-621b7f558e03).
Successfully sent initial files for device %H:%M:%S (84033bdf-d3d6-43a3-9857-621b7f558e03).
LOG from device %H:%M:%S: com.tns.NativeScriptException: Error calling module function
Error: Type AppRoutingModule does not have 'ngModuleDef' property.
File: (file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1682:12)

StackTrace:
ZoneAwareError(file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:1298:33)
at getNgModuleDef(file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1682:19)
at (file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1513:31)
at noSideEffects(file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1321:19)
at ����setNgModuleScope(file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:1512:16)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:39:131)
at ./app/app-routing.module.tns.ts(file:///data/data/org.nativescript.preview/files/app/bundle.js:39:339)
at webpack_require(file:///data/data/org.nativescript.preview/files/app/runtime.js:817:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at ./app/app.module.tns.ts(file:///data/data/org.nativescript.preview/files/app/bundle.js:94:85)
at webpack_require(file:///data/data/org.nativescript.preview/files/app/runtime.js:817:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:208:77)
at ./main.tns.ts(file:///data/data/org.nativescript.preview/files/app/bundle.js:273:30)
at webpack_require(file:///data/data/org.nativescript.preview/files/app/runtime.js:817:30)
at checkDeferredModules(file:///data/data/org.nativescript.preview/files/app/runtime.js:44:23)
at webpackJsonpCallback(file:///data/data/org.nativescript.preview/files/app/runtime.js:31:19)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:2:57)
at require(:1:266)

Error: Type AppRoutingModule does not have 'ngModuleDef' property.
at com.tns.Runtime.runModule(Native Method)
at com.tns.Runtime.runModule(Runtime.java:674)
at com.tns.Runtime.run(Runtime.java:666)
at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5448)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1564)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6186)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

@mahmoudajawad
Copy link

@betosalvador, I'm not having any authority here but I suggest you open an issue, and link it here to continue checking this with you. I believe we can have a look at your project to get some ideas on what's going on. Also, try running tns preview --no-hmr and report the results in the new issue.

@betosalvador
Copy link

Thanks @mahmoudajawad

I did open a new issue #290

👍

@NathanWalker
Copy link
Contributor Author

Thanks @mahmoudajawad - yep @betosalvador {N} Preview app just needs Angular 10 updates as well so we're working on getting that update in review 👍

@betosalvador
Copy link

@NathanWalker thanks man

I:) 👍

@cjohn001
Copy link

cjohn001 commented Sep 16, 2020

Hello together, I am just trying to get a NS Angular 10 project set up. I followed the description here from @NathanWalker and the one on the nativescript schematics github page. Unfortunately I cannot get a seed running. What I did:

npm i -g nativescript --> nativescript@7.0.8
npm i -g @nativescript/schematics --> @nativescript/schematics@10.1.0
npm i -g @angular/cli --> @angular/cli@10.1.1

create project:
ng new --collection=@nativescript/schematics sample-ns7-app3-schematics --style=scss

tried to run:
ns run ios --emulator --no-hmr
ns run ios --emulator --no-hmr --env.aot

Error message:
ERROR in error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option.

I tried to add a baseUrl to tsconfig.json, but then I get a different error:
"compilerOptions": {
"baseUrl": "./",
}

Webpack build done!
cp: no such file or directory: /Users/cjohn/Entwicklung/IMS_Help/sample-ns7-app3-schematics/App_Resources/iOS/*

Did someone manage to get an Angular 10 project (ios and angular, no web) set up with scss support and can tell me how to do it? Thanks for your help.

@mahmoudajawad
Copy link

@cjohn001, have you tried creating NG project then adding NS to it?

@cjohn001
Copy link

Hello @mahmoudajawad,
no I have not, as to my understanding the result froom it would differ from what I want achive. To my understanding with ng I create a webproject and than add ns ios and android to it. (same as using ns with --shared option). What I want is nativescript 7 android and ios projects only, but with scss support (hence being able to split scss files into *.ios.scss and *.android.scss). Is my understanding of the situation wrong? Thanks for your feedback

@mahmoudajawad
Copy link

I see. If you want mobile-only app, which I do all the time, then you can just go the following path:

ns create --ng ns7ng10

though, this would create CSS-styled project, but I believe you can use the same method for migrating Angular projects to SCSS in this new project.

@rob4226
Copy link

rob4226 commented Oct 30, 2020

@mahmoudajawad @NathanWalker I'm also having a problem with unit testing. I was using the docs as a reference but I get the error:

ERROR in src/tests/example.spec.ts:12:9 - error NG8001: 'StackLayout' is not a known element:

  1. If 'StackLayout' is an Angular component, then verify that it is part of this module.
  2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
    <StackLayout><Label text="Layout"></Label></StackLayout>

Is there any way to add NO_ERRORS_SCHEMA to the Angular TestBed that is created with nsTestBedInit()?

The work around I am using right now is treating my components as EntryComponents so I can create my own module with NO_ERRORS_SCHEMA like TestBed.initTestEnvironment(MyEntryComponentsTestModule) which works but there has to be a better and easier way.

Also, the docs say import the following but it does not exist in that place in NativeScript 7. Does anyone know where this file is located now?

import "nativescript-angular/zone-js/testing.jasmine";

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

7 participants