简体   繁体   中英

Angular issue on exisiting project

I'm on Windows 7.

I imported an Angular project started by a friend, but I had some issue after installing node and angular, I was able to run the project with this command:

C:\NG\projectName>npm start

But when I try to generate a new component with this command I get an error:

C:\NG\projectName\app\components>ng g c myNewComponentName
installing component
Unable to find any apps in `.angular-cli.json`

The angular-cli.json file is located here: C:\\NG\\projectName\\node_modules\\@angular\\cli\\blueprints\\ng\\files\\ and contains this code:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "<%= htmlComponentName %>"
  },
  "apps": [
    {
      "root": "<%= sourceDir %>",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "<%= prefix %>",
      "styles": [
        "styles.<%= styleExt %>"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "<%= sourceDir %>/tsconfig.app.json"
    },
    {
      "project": "<%= sourceDir %>/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "<%= styleExt %>",<% if (!minimal) { %>
    "component": {}<% } else { %>
    "component": {
      "spec": false,
      "inlineStyle": true,
      "inlineTemplate": true
    },
    "directive": {
      "spec": false
    },
    "class": {
      "spec": false
    },
    "guard": {
      "spec": false
    },
    "module": {
      "spec": false
    },
    "pipe": {
      "spec": false
    },
    "service": {
      "spec": false
    } <% } %>
  }
}

How can I fix that?

For information:

C:\NG\projectName\app\components>ng -v
@angular/cli: 1.2.0
node: 6.11.0
os: win32 x64
@angular/animations: 4.2.5
@angular/common: 4.2.5
@angular/compiler: 4.2.5
@angular/compiler-cli: 4.2.5
@angular/core: 4.2.5
@angular/forms: 4.2.5
@angular/http: 4.2.5
@angular/platform-browser: 4.2.5
@angular/platform-browser-dynamic: 4.2.5
@angular/platform-server: error
@angular/router: 4.2.5
@angular/tsc-wrapped: 4.0.3
@angular/upgrade: error
@angular/cli: 1.2.0

C:\NG\projectName\app\components>npm -v
3.10.10

thank you for your help.

The problem is most likely that the project was not initialized with the angular cli.

Running ng init in C:\\NG\\projectName> should solve the problem ¹

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM