cornflourblue / angular-7-jwt-authentication-example

Angular 7 JWT Authentication Example
http://jasonwatmore.com/post/2018/11/16/angular-7-jwt-authentication-example-tutorial
MIT License
116 stars 97 forks source link

Unable to add new componet #1

Open dev01prishusoft opened 5 years ago

dev01prishusoft commented 5 years ago

Hi

When I tried to add a new component with the following syntax

ng g c component-name it give me error as below

You have to be inside an angular-cli project in order to use the generate command.

PierreDemailly commented 5 years ago

This is because this repo don't use angular client (I wonder why...) Run npm i @angular/cli then create angular.json file at your project root with this content: (change you're project name, etc) { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "projects": { "project": { "root": "", "sourceRoot": "src", "projectType": "application", "prefix": "app", "schematics": { "@schematics/angular:component": { "styleext": "scss" } }, "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/project", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ], "scripts": [] }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" } ] } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "project:build" }, "configurations": { "production": { "browserTarget": "project:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "project:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json", "karmaConfig": "src/karma.conf.js", "styles": [ "src/styles.scss" ], "scripts": [], "assets": [ "src/favicon.ico", "src/assets" ] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "src/tsconfig.app.json", "src/tsconfig.spec.json" ], "exclude": [ "**/node_modules/**" ] } } } }, "project-e2e": { "root": "e2e/", "projectType": "application", "prefix": "", "architect": { "e2e": { "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "e2e/protractor.conf.js", "devServerTarget": "project:serve" }, "configurations": { "production": { "devServerTarget": "project:serve:production" } } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": "e2e/tsconfig.e2e.json", "exclude": [ "**/node_modules/**" ] } } } } }, "defaultProject": "project" } Then run ng update Then run ng g c component-name, it will return an error like

Cannot find module '@angular/compiler-cli' Error: Cannot find module '@angular/compiler-cli'

Fix it with npm i @angular/compiler-cli (adapt with the error) and repeat untill it works.

mehars-jalin commented 5 years ago

This project is available in both webpack and angular CLI flavor, for CLI version check this one out : https://github.com/cornflourblue/angular-7-registration-login-example-cli