NativeScript Importing NGXS module in app.module throw an error in log console - nativescript

I'm new with NativeScript and I want to use a state management NGXS and implement to my app. I have installed NGXS with NPM: #ngxs/store #ngxs/logger-plugin and #ngxs/devtools-plugin.
So I added those NGXS module to my app.module.
import { NgModule, NO_ERRORS_SCHEMA } from "#angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { NativeScriptUISideDrawerModule } from "nativescript-ui-sidedrawer/angular";
import { NgxsModule } from '#ngxs/store';
import { NgxsLoggerPluginModule } from '#ngxs/logger-plugin';
import { NgxsReduxDevtoolsPluginModule } from '#ngxs/devtools-plugin';
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { PetState } from './_ngxs/pet/pet.state';
#NgModule({
bootstrap: [
AppComponent
],
imports: [
AppRoutingModule,
NativeScriptModule,
NativeScriptUISideDrawerModule,
NgxsModule.forRoot([
//if i uncomment PetState, in console log show me error, Failed to find module: "./pet.actions"
// PetState
]),
//if i uncomment `NgxsLoggerPluginModule.forRoot()`, in console log show me error, Failed to find module: "#ngxs/logger-plugin
// NgxsLoggerPluginModule.forRoot(),
//if i uncomment `NgxsReduxDevtoolsPluginModule.forRoot()`, in console log show me error, Failed to find module: "#ngxs/devstool-plugin
// NgxsReduxDevtoolsPluginModule.forRoot()
],
declarations: [
AppComponent
],
schemas: [
NO_ERRORS_SCHEMA
]
})
export class AppModule { }
After I added the ngxs module, I got 2 issues.
under NgxsModule.forRoot if I uncomment PetState it throw me error in console log, Failed to find module: "./pet.actions". Please refer
If I uncomment NgxsLoggerPluginModule.forRoot() / NgxsReduxDevtoolsPluginModule.forRoot() I will get error in console log and saying failed to find module #ngxs/logger-plugin / #ngxs/devstool-plugin
below is pet.state.ts codes
import { State, Action, Selector, StateContext } from '#ngxs/store';
import { Pet } from './pet.model';
import { AddPet, RemovePet } from './pet.actions';
export class PetStateModel {
pets: Pet[];
}
#State<PetStateModel>({
name: 'Pet',
defaults: {
pets: []
}
})
export class PetState {
#Selector()
static getPet(state: PetStateModel) {
return state.pets;
}
#Action(AddPet)
addPet({getState, patchState}: StateContext<PetStateModel>, { payload }: AddPet) {
const state = getState();
patchState({
pets: [...state.pets, payload]
})
}
#Action(RemovePet)
removePet({getState, patchState}: StateContext<PetStateModel>, { payload }: RemovePet) {
const state = getState();
patchState({
pets: state.pets.filter(a => a.name !== payload )
})
}
}
I really need someone can give some hand to help me fix the issues,
thanks,
Updated
here is my package.json
{
"nativescript": {
"id": "org.nativescript.pledgeCareSample",
"tns-android": {
"version": "5.2.1"
},
"tns-ios": {
"version": "5.2.0"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"scripts": {
"lint": "tslint \"src/**/*.ts\""
},
"dependencies": {
"#angular/animations": "~7.2.0",
"#angular/common": "~7.2.0",
"#angular/compiler": "~7.2.0",
"#angular/core": "~7.2.0",
"#angular/forms": "~7.2.0",
"#angular/http": "~7.2.0",
"#angular/platform-browser": "~7.2.0",
"#angular/platform-browser-dynamic": "~7.2.0",
"#angular/router": "~7.2.0",
"#ngxs/storage-plugin": "^3.4.3",
"#ngxs/store": "^3.4.3",
"nativescript-angular": "~7.2.1",
"nativescript-theme-core": "~1.0.4",
"nativescript-ui-sidedrawer": "~5.1.0",
"nativescript-unit-test-runner": "^0.6.0",
"reflect-metadata": "~0.1.12",
"rxjs": "~6.3.0",
"tns-core-modules": "~5.2.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"#angular/compiler-cli": "~7.2.0",
"#nativescript/schematics": "~0.5.0",
"#ngtools/webpack": "~7.2.0",
"#ngxs/devtools-plugin": "^3.4.3",
"#ngxs/logger-plugin": "^3.4.3",
"#types/jasmine": "^3.3.12",
"codelyzer": "~4.5.0",
"karma": "4.0.1",
"karma-jasmine": "2.0.1",
"karma-nativescript-launcher": "0.4.0",
"nativescript-dev-sass": "~1.6.0",
"nativescript-dev-typescript": "~0.8.0",
"nativescript-dev-webpack": "~0.20.0",
"tslint": "~5.11.0"
},
"gitHead": "f548ec926e75201ab1b7c4a3a7ceefe7a4db15af",
"readme": "NativeScript Application"
}

Ok I found the solution. After few hours I found this solution here and with my solutions
Just need to remove node_modules, hook and platform folder then npm i and add the platform for both ios and android.
and 1 more thing I am not sure why, I uninstalled for #ngxs/logger-plugin and #ngxs/devtools-plugin and reinstall back to the dependency not in dev dependency.
anyway, for now it work for me.

Related

Nativescript cannot find module '#nativescript/angular/router'

I am developing an app using nativescript and angular 11.0. For initial startup creating a login screen. Facing issues while running the application. Get the below exception. The issue happens only when routing is enabled in the module.
ERROR in ./app/login/login.component.ts
Module not found: Error: Can't resolve '#nativescript/angular/router' in 'D:\Mobile_dev\ns-ng-quiz\app-ns-ng\src\app\login'
# ./app/login/login.component.ts 3:0-64 5:0-51 40:113-132 78:38-57
# ./app/app.module.ts
# ./main.ts
ng update says everything is in order. Deleting node_modules folder and a fresh npm install did not help either.
Here is my package.json
{
"name": "#nativescript/template-hello-world-ng",
"main": "main.js",
"version": "7.0.8",
"author": "NativeScript Team <oss#nativescript.org>",
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"publishConfig": {
"access": "public"
},
"keywords": [
"nativescript",
"mobile",
"angular",
"{N}",
"template"
],
"repository": {
"type": "git",
"url": "<fill-your-repository-here>"
},
"bugs": {
"url": "https://github.com/NativeScript/NativeScript/issues"
},
"dependencies": {
"#angular/animations": "~11.0.0",
"#angular/common": "~11.0.0",
"#angular/compiler": "~11.0.0",
"#angular/core": "~11.0.0",
"#angular/forms": "~11.0.0",
"#angular/platform-browser": "~11.0.0",
"#angular/platform-browser-dynamic": "~11.0.0",
"#angular/router": "~11.0.0",
"#nativescript/angular": "~11.0.0",
"#nativescript/core": "~7.0.0",
"#nativescript/theme": "~3.0.0",
"reflect-metadata": "~0.1.12",
"rxjs": "^6.6.0",
"zone.js": "~0.11.1"
},
"devDependencies": {
"#angular/compiler-cli": "~11.0.0",
"#nativescript/android": "7.0.1",
"#nativescript/types": "~7.0.0",
"#nativescript/webpack": "~3.0.0",
"#ngtools/webpack": "~11.0.0",
"typescript": "~4.0.0"
},
"private": "true",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
Here is my app-routing.module.ts
import { LoginComponent } from './login/login.component';
import { HomeComponent } from './home/home.component';
import { NgModule } from "#angular/core";
import { Routes } from "#angular/router";
import { NativeScriptRouterModule } from "#nativescript/angular";
import { ItemsComponent } from "./item/items.component";
import { ItemDetailComponent } from "./item/item-detail.component";
const routes: Routes = [
{path: "", redirectTo: "/login", pathMatch: "full" },
{path:"login", component:LoginComponent},
{path:"home", component:HomeComponent}
//{ path: "", redirectTo: "/items", pathMatch: "full" },
// { path: "items", component: ItemsComponent },
// { path: "item/:id", component: ItemDetailComponent }
];
#NgModule({
imports: [NativeScriptRouterModule.forRoot(routes,{
enableTracing:true
})],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }
Project Structure in VSCode
You should be able to import both RouterExtensions for navigation and NativeScriptRouterModule in the module from #nativescript/angular instead of the previous #nativescript/angular/router path.
import { RouterExtensions } from '#nativescript/angular'

nativescript ios app crashes - attempting to change the getter of an unconfigurable property

I created a directive to disable the context menu on android and ios app in Nativescript.
import { Directive, OnInit, OnDestroy, ElementRef, Renderer2 } from "#angular/core";
import { isIOS } from "tns-core-modules/platform";
import * as utils from "tns-core-modules/utils/utils";
import { EventData } from "tns-core-modules/data/observable";
import { TextField } from "tns-core-modules/ui/text-field";
declare var UITextField, CGRectMake, android;
if (isIOS) {
UITextField.prototype._originalCanPerformActionWithSender = UITextField.prototype.canPerformActionWithSender;
UITextField.prototype.canPerformActionWithSender = function (action, sender) {
if (this.disableMenu) {
return false;
}
return UITextField.prototype._originalCanPerformActionWithSender.call(this, action, sender)
};
}
#Directive({
selector: "[disableCutCopyPaste]"
})
export class DisableCutCopyPasteDirective implements OnInit, OnDestroy {
listener: () => void;
constructor(private renderer: Renderer2, private el: ElementRef) {
}
ngOnInit() {
this.listener = this.renderer.listen(this.el.nativeElement, TextField.loadedEvent, (event: EventData) => {
const textField = <TextField>event.object;
if (isIOS) {
Object.defineProperty(textField.nativeView, "disableMenu", {
get: function () {
return true;
}
});
} else {
textField.nativeView.setLongClickable(false);
textField.nativeView.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function (view, event) {
if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
view.requestFocus();
utils.ad.showSoftInput(view);
}
return true;
}
}));
}
});
}
ngOnDestroy() {
this.removeListener();
}
private removeListener() {
if (this.listener) {
this.listener();
this.listener = null;
}
}
}
This code is working fine on Android devices but the iOS app is crashing and I'm getting the following error
TypeError: Attempting to change the getter of an unconfigurable property
at this line
Object.defineProperty(textField.nativeView, "disableMenu", {
Can anyone tell me what's causing this issue?
My package.json
{
"nativescript": {
"id": "com.abcde.app",
"tns-android": {
"version": "6.1.1"
},
"tns-ios": {
"version": "6.5.3"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"dependencies": {
"#angular/animations": "~8.2.9",
"#angular/common": "~8.2.9",
"#angular/compiler": "~8.2.9",
"#angular/core": "~8.2.9",
"#angular/forms": "~8.2.9",
"#angular/http": "8.0.0-beta.10",
"#angular/platform-browser": "~8.2.9",
"#angular/platform-browser-dynamic": "~8.2.9",
"#angular/router": "~8.2.9",
"#nstudio/nativescript-checkbox": "^1.0.0",
"#nstudio/nativescript-loading-indicator": "^1.0.0",
"nativescript-angular": "^8.2.1",
"nativescript-carousel": "^6.1.1",
"nativescript-checkbox": "^3.0.3",
"nativescript-drop-down": "^5.0.4",
"nativescript-exit": "^1.0.1",
"nativescript-floatingactionbutton": "^5.1.0",
"nativescript-iqkeyboardmanager": "^1.5.1",
"nativescript-modal-datetimepicker": "^1.2.3",
"nativescript-plugin-firebase": "^10.0.1",
"nativescript-root-detection": "^1.0.0",
"nativescript-theme-core": "~1.0.4",
"nativescript-ui-listview": "7.1.0",
"reflect-metadata": "~0.1.13",
"rxjs": "^6.5.3",
"rxjs-compat": "^6.5.3",
"simple-crypto-js": "^2.2.0",
"tns-core-modules": "^6.5.21",
"tns-platform-declarations": "^6.5.15",
"zone.js": "0.9.1"
},
"devDependencies": {
"#angular/compiler-cli": "8.2.9",
"#nativescript/schematics": "~0.7.2",
"#ngtools/webpack": "8.3.8",
"nativescript-dev-webpack": "^1.3.0",
"tns-android": "6.1.1",
"typescript": "~3.5.3"
},
"gitHead": "9b65dfgdgdfgdgdgdfgdfd818a8205e",
"readme": "NativeScript Application"
}
Playground Link

Use cucumber and XRAY in protractor

I'm using Cucumber in my project with protractor and now I want to integrate it with Jira using XRAY but looking at the documentation, it uses jasmine and I don't know how to use both frameworks because if I put the code as indicated in the documentation using the "jasmine" framework instead of "custom" it doesn't recognize the cucumber sentences of the features.
Can someone help me? Thanks in advance
I include package.json and xrayconfig.ts .
xrayconfig.ts:
import { Config, protractor } from 'protractor';
import * as reporter from "cucumber-html-reporter";
import 'jasmine';
const XrayReporter = require('protractor-xray-reporter');
let onPrepareDefer;
let onCompleteDefer;
export let config: Config = {
directConnect: true,//Running chrome
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
frameworkPath: require.resolve('protractor-cucumber-framework'),
"types": ["chai", "cucumber", "node"],
specs: ['../Features/*.feature'],
cucumberOpts: {
tags:"#scenarioLola", //only executed this scenario
require: [
'../JSFiles/stepDefinitions/*.js' // accepts a glob
]
},
'onPrepare': function() {
let globals = require('protractor');
let browser = globals.browser;
onPrepareDefer = protractor.promise.defer();
onCompleteDefer = protractor.promise.defer();
const options = {
'screenshot': 'always',
'version': '1.0',
'jiraUser': 'user',
'jiraPassword': 'pwd',
'xrayUrl': 'https://jira.com/rest/raven/1.0/import/execution'
};
jasmine.getEnv().addReporter(XrayReporter(options, onPrepareDefer, onCompleteDefer, browser));
return onPrepareDefer.promise;
},
'onComplete': function() {
return onCompleteDefer.promise;
}
};
package.json
{
"name": "project",
"version": "1.0.0",
"description": "Project one",
"main": "index.js",
"scripts": {
"test": "protractor JSFiles/cucumberconfig.js",
"pretest": "tsc",
"protractor": "./node_modules/protractor/built/cli.js",
"webdriver-update": "./node_modules/.bin/webdriver-manager update"
},
"author": "Carol",
"license": "ISC",
"dependencies": {
"#types/cucumber": "^6.0.1",
"#types/jasmine": "^3.5.11",
"#types/jasminewd2": "2.0.8",
"#types/node": "^14.0.13",
"#types/jest": "^26.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cucumber": "^6.0.5",
"cucumber-html-reporter": "^5.2.0",
"jasmine": "~3.5.0",
"protractor-cucumber-framework": "^6.2.1",
"typescript": "~3.9.5",
"protractor-jasmine2-screenshot-reporter": "0.5.0"
},
"devDependencies": {
"install-peers": "^1.0.3",
"protractor": "^7.0.0",
"protractor-zephyr-reporter": "^1.2.1",
"ts-node": "^8.10.2",
"jasmine-spec-reporter": "5.0.2",
"jasmine-core": "3.5.0"
}
}

Angular 6 Material StaticInjectorError NgZone

After migrating from Angular 5 to Angular 6 all my Material component do not work anymore - again... ...yet this time I am really clueless about what could cause the problem anymore. I invested half a day investigating and created a stripped-down project in order to reproduce the problem in its essence.
Let me show you the various file contents:
package.json
{
"name": "xxx",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^6.0.9",
"#angular/cdk": "^6.4.0",
"#angular/common": "^6.0.9",
"#angular/compiler": "^6.0.9",
"#angular/core": "^6.0.9",
"#angular/forms": "^6.0.9",
"#angular/http": "^6.0.9",
"#angular/material": "^6.4.0",
"#angular/platform-browser": "^6.0.9",
"#angular/platform-browser-dynamic": "^6.0.9",
"#angular/platform-server": "^6.0.9",
"#angular/router": "^6.0.9",
"#ngtools/webpack": "1.8.0",
"#types/node": "~6.0.60",
"#types/webpack-env": "1.13.0",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"codelyzer": "~3.2.0",
"css": "2.2.1",
"css-loader": "0.28.4",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.9",
"expose-loader": "0.7.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"html-loader": "0.4.5",
"isomorphic-fetch": "2.2.1",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"preboot": "4.5.2",
"protractor": "~5.1.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "^6.2.2",
"style-loader": "0.18.2",
"to-string-loader": "1.1.5",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.7.2",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"#angular/cli": "^6.0.8",
"#angular/compiler-cli": "^6.0.9",
"#angular/language-service": "^6.0.9",
"#types/node": "~6.0.60",
"codelyzer": "~3.2.0",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0"
}
}
app.module
import { NgModule } from '#angular/core';
import { MatDialogModule } from '#angular/material';
import { CommonModule } from '#angular/common';
import { RouterModule } from '#angular/router';
import { AppComponent } from './components/app/app.component';
import { MessageFormComponent } from './components/common/forms/message.component';
#NgModule({
declarations: [
AppComponent,
MessageFormComponent,
],
imports: [
CommonModule,
MatDialogModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: MessageFormComponent },
{ path: '**', redirectTo: 'home' }
]),
]
})
export class AppModuleShared {
}
message.component.ts
import { Component } from '#angular/core';
import { MatDialog, MAT_DIALOG_DATA } from '#angular/material';
#Component({
selector: 'message-form',
template: 'blubb',
})
export class MessageFormComponent {
constructor(private alert: MatDialog) { } // this line causes the problem
}
As soon as I make ANYTHING with the material - this error occurs. I am good in programming angular programs - not so good in fiddling around with the NEVER WORKING infrastructure... ;-)

Cannot find module 'rxjs/testing' from 'jasmine-marbles.umd.js'

I am currently want to test my effects with ngrx/effects. I followed the markdown but I have an error when I want run my test.
Cannot find module 'rxjs/testing' from 'jasmine-marbles.umd.js'
Here is my code (For the moment I did not do expectations, I just want my test runs) :
import { TestBed } from '#angular/core/testing'
import { provideMockActions } from '#ngrx/effects/testing'
import { ReplaySubject } from 'rxjs/ReplaySubject'
import { hot, cold } from 'jasmine-marbles'
import { Observable } from 'rxjs/Observable'
import { VersionService } from '../../service/version/version.service'
import { DataEffects } from './data.effect'
import { RequestVersions, ReceiveVersions } from './data.action'
describe('My Effects', () => {
let versionService: VersionService
let effects: DataEffects
let actions: Observable<any>
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
// any modules needed
],
providers: [
DataEffects,
provideMockActions(() => actions),
{provide: VersionService, useValue: {
getVersions: jest.fn().mockReturnValueOnce({data: {versions: 'MOCKED_VERSION_RESULT'}})
}}
],
})
versionService = TestBed.get(VersionService)
effects = TestBed.get(DataEffects)
})
it('should work', () => {
const action = new RequestVersions()
const completion = new ReceiveVersions('MOCKED_VERSION_RESULT')
actions = hot('--a-', { a: action });
const expected = cold('--b', { b: completion })
})
}
And here what my package.json look like :
[...]
"dependencies": {
[... all #angular import ...]
"#ngrx/effects": "^5.2.0",
"#ngrx/store": "^5.2.0",
"#ngrx/store-devtools": "^5.2.0",
"bootstrap": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"#angular/cli": "1.6.7",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"#types/jest": "^22.1.4",
"#types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-marbles": "^0.3.0",
"jest": "^22.4.2",
"jest-junit": "^3.6.0",
"jest-preset-angular": "^5.2.0",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
[...]
Can anyone help me in this matter ?
Just ran into this as well.
In my case using jasmine-marbles#v0.2.0 instead of the #latest resolve it, since it doesn't seem to require the peer dependency of the beta rxjs 6 release

Resources