javapedia.net
javapedia.net

Reputation: 2731

Nativescript Angular error NG8001: 'StackLayout' is not a known element:

ERROR in src/app/components/dashboard/dashboard.component.html:1:1 - error NG8001: 'StackLayout' is ot 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.

1

dashboard.component.tns.html

<StackLayout>
  <Label text="dashboard works" textWrap="true"></Label>
  <Label text="This is a migrated component" textWrap="true"></Label>
  <Label text="Update it to provide the UI elements required in your mobile app" textWrap="true"></Label>
</StackLayout>

package.json

{
  "name": "angular-google-identity",
  "version": "0.0.0",
  "scripts": {
    "android": "ns run android --no-hmr",
    "ios": "ns run ios --no-hmr",
    "mobile": "ns run",
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "eslint": "eslint 'src/**/*.ts'",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^10.1.5",
    "@angular/common": "~10.0.9",
    "@angular/compiler": "~10.0.9",
    "@angular/core": "~10.0.9",
    "@angular/forms": "~10.0.9",
    "@angular/localize": "~10.0.9",
    "@angular/platform-browser": "~10.0.9",
    "@angular/platform-browser-dynamic": "~10.0.9",
    "@angular/router": "~10.0.9",
    "@angular/service-worker": "~10.0.9",
    "@nativescript/angular": "~10.1.0",
    "@nativescript/core": "~7.0.0",
    "@nativescript/theme": "~2.5.0",
    "@ng-bootstrap/ng-bootstrap": "^7.0.0",
    "@stomp/ng2-stompjs": "^7.2.0",
    "@types/node-rsa": "^1.0.0",
    "@types/socket.io-client": "^1.4.33",
    "aes-js": "^3.1.2",
    "angularx-social-login": "^3.2.1",
    "bootstrap": "^4.5.0",
    "constants": "0.0.2",
    "core-js": "^3.6.5",
    "crypto": "^1.0.1",
    "event-source-polyfill": "^1.0.16",
    "idb": "^5.0.4",
    "mediasoup-client": "^3.6.12",
    "moment": "^2.27.0",
    "nativescript-secure-storage": "^2.6.2",
    "ng-gapi": "0.0.93",
    "ngx-avatar": "^4.0.0",
    "ngx-contextmenu": "^5.4.0",
    "ngx-infinite-scroll": "^9.0.0",
    "ngx-link-preview": "^1.1.6",
    "ngx-logger": "^4.1.9",
    "ngx-webcam": "^0.3.0",
    "node-rsa": "^1.1.1",
    "primeng": "^10.0.0-rc.3",
    "recordrtc": "^5.6.1",
    "reflect-metadata": "~0.1.12",
    "rxjs": "~6.6.2",
    "rxjs-compat": "^6.6.3",
    "secure-ls": "^1.2.6",
    "socket.io": "^2.3.0",
    "socket.io-client": "^2.3.0",
    "stompjs": "^2.3.3",
    "tslib": "^2.0.1",
    "webrtc-adapter": "^7.7.0",
    "zone.js": "~0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1000.6",
    "@angular/cli": "~10.0.6",
    "@angular/compiler-cli": "~10.0.9",
    "@angular/language-service": "~10.0.9",
    "@nativescript/android": "7.0.0",
    "@nativescript/schematics": "^10.1.0",
    "@nativescript/tslint-rules": "~0.0.5",
    "@nativescript/webpack": "~3.0.0",
    "@types/jasmine": "~3.5.12",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^14.6.0",
    "@typescript-eslint/eslint-plugin": "^4.1.0",
    "@typescript-eslint/eslint-plugin-tslint": "^3.9.1",
    "@typescript-eslint/parser": "^4.1.0",
    "codelyzer": "~6.0.0",
    "eslint": "^7.8.1",
    "eslint-config-google": "^0.14.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.2",
    "karma": "~5.1.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "~4.0.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "protractor": "^7.0.0",
    "ts-node": "~8.10.2",
    "tslint": "~6.1.3",
    "typescript": "~3.9.7"
  },
  "main": "main.tns.js"
}

Also app.module.tns.ts also has schemas: [NO_ERRORS_SCHEMA]

Encounter the error when running tns build android --bundle

Upvotes: 3

Views: 3198

Answers (4)

Davis Jahn
Davis Jahn

Reputation: 573

For me it was a missing declaration of a ModalComponent in my component.module because I was working with Nativescript ModalDialogService. After adding it, everything worked fine.

@NgModule({
imports: [
    IntranetRoutingModule,
    //SharedModule
],
declarations: [
    IntranetComponent,
    IntranetModalComponent // <- This one was missing
],
entryComponents: [IntranetModalComponent],
providers: [ModalDialogService],
schemas: [
    NO_ERRORS_SCHEMA
]

})

Upvotes: 0

Ricky Levi
Ricky Levi

Reputation: 7997

Wanted to add another answer for those using lazy mode. During the upgrade from old version of NativeScript, I had an error in the modules file: mypage.module.ts

So I changed:

import { NativeScriptCommonModule } from "nativescript-angular/common";

To:

import { NativeScriptCommonModule } from "@nativescript/angular";

That error, made an impact across the entire page ...

The accepted answer gave me the clue from where to start looking...

Upvotes: 2

Otpidus
Otpidus

Reputation: 519

Quick solution as of now: Declare Components with Module and include schemas:[NO_ERRORS_SCHEMA].

Like so: \TestComponent - TestComponent.html - TestComponent.ts - TestComponent.module.ts <= This should have the schemas:[NO_ERRORS_SCHEMA]

Upvotes: 0

javapedia.net
javapedia.net

Reputation: 2731

Just realized the app.module.tns.ts doesn't have the Dashboard component declared which resolves the issue.

@NgModule({
  declarations: [
    AppComponent,
    AutoGeneratedComponent,
    DashboardComponent
  ],

Upvotes: 4

Related Questions