Platform: generate not working on existing project

Created on 31 Mar 2018  路  11Comments  路  Source: ngrx/platform

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

What is the current behavior?

I am trying to use the generator on an existing project, and I am getting the following errors.

ng generate store State --root --module app.module.ts --collection @ngrx/schematics

Error: Path "/__path__/__statePath__/index.ts" does not exist.
Path "/__path__/__statePath__/index.ts" does not exist.
ng generate effect App --root --module app.module.ts --collection @ngrx/schematics

Error: Path "/__path__/__name@dasherize@if-flat__/__name@dasherize__.effects.ts" does not exist.

Expected behavior:

Minimal reproduction of the problem with instructions:

Version of affected browser(s),operating system(s), npm, node and ngrx:

Other information:

All 11 comments

Can you provide more information? What version of the CLI are you using?

Angular CLI: 1.7.3
Node: 9.10.0
OS: darwin x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.2.4
@angular/cli: 1.7.3
@angular/material: 5.2.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.4.8
@angular-devkit/schematics: 0.4.8
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.4.8
@schematics/package-update: 0.4.8
typescript: 2.5.3
webpack: 3.11.0

I have also tried on 1.7.2, 1.6.8 and no difference

ng generate container ComponentName --collection @ngrx/schematics

Error: Could not find (undefined)
Could not find (undefined)

This also fails

Is this with a newly generated project with Angular CLI 1.7? Will you share your package.json

This is not a new project

{
  "name": "frontend",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0 --disable-host-check",
    "start-local": "ng serve --env local --host 0.0.0.0 --disable-host-check ",
    "start-dev-prod": "ng serve --env dev-prod --host 0.0.0.0 --disable-host-check ",
    "start-prod": "ng serve --env prod --prod --host 0.0.0.0 --disable-host-check ",
    "start-local-aot": "ng serve --env local --host 0.0.0.0 --disable-host-check --aot",
    "start-dev-prod-aot": "ng serve --env dev-prod --host 0.0.0.0 --disable-host-check --aot",
    "start-prod-aot": "ng serve --env prod --prod --host 0.0.0.0 --disable-host-check --aot",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/core": "^0.4.8",
    "@angular/animations": "^5.2.0",
    "@angular/cdk": "^5.2.4",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/material": "^5.2.4",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@defvayne23/svg-marker": "^0.7.0",
    "@ng-bootstrap/ng-bootstrap": "^1.1.0",
    "@ngrx/effects": "^5.2.0",
    "@ngrx/router-store": "^5.2.0",
    "@ngrx/store": "^5.2.0",
    "@ngrx/store-devtools": "^5.2.0",
    "@ngui/map": "^0.21.1",
    "@types/tinycolor2": "^1.4.0",
    "angular2-jwt": "^0.2.3",
    "angular2-moment": "^1.8.0",
    "bootstrap": "^4.0.0",
    "bootstrap-float-label": "^3.0.1",
    "color": "^3.0.0",
    "core-js": "^2.5.4",
    "d3-scale": "^2.0.0",
    "d3-scale-chromatic": "^1.2.0",
    "datamaps": "^0.5.8",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jquery-slim": "^3.0.0",
    "lodash": "^4.17.5",
    "loglevel": "^1.6.1",
    "moment": "^2.21.0",
    "ngx-pipes": "^2.1.2",
    "ngx-toastr": "^8.3.2",
    "normalizr": "^3.2.4",
    "npm": "^5.8.0",
    "popper.js": "^1.14.1",
    "raven-js": "^3.24.0",
    "reselect": "^3.0.1",
    "rxjs": "^5.5.8",
    "seamless-immutable": "^7.1.3",
    "svg.js": "^2.6.4",
    "tinycolor2": "^1.4.1",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular-devkit/schematics": "^0.4.8",
    "@angular/cli": "~1.7.3",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@ngrx/schematics": "^5.2.0",
    "@schematics/angular": "^0.4.8",
    "@schematics/package-update": "^0.4.8",
    "@types/googlemaps": "^3.30.8",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/lodash": "^4.14.106",
    "@types/loglevel": "^1.5.3",
    "@types/node": "~6.0.60",
    "@types/seamless-immutable": "^7.1.1",
    "codelyzer": "^4.2.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.2",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "moment-timezone": "^0.5.14",
    "protractor": "~5.1.2",
    "registry-url": "^3.1.0",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}

I have update almost all the packages to match 1.7.3 build.

I would suggest removing the pinned versions of @angular-devkit/core, @angular-devkit/schematics and let them get installed with the versions used by the @angular/cli. I tried generating a new clean project from the CLI with 1.7.x and it works as designed.

@brandonroberts I can't get it to work even with a fresh app. Did I miss a step? I'm on Windows 10. Tried this with no success:

$ ng new tmp-app
$ cd ./tmp-app
$ npm install --save @ngrx/core @ngrx/effects @ngrx/store
$ npm install --save-dev @ngrx/schematics
$ ng generate store State --root --module app.module.ts --collection @ngrx/schematics
Error: Cannot find module '@angular-devkit/schematics'
$ npm install --save-dev @angular-devkit/schematics
$ ng generate store State --root --module app.module.ts --collection @ngrx/schematics

Error: Path "/__path__/__statePath__/index.ts" does not exist.
Path "/__path__/__statePath__/index.ts" does not exist.

$ npm install --save-dev @angular-devkit/core
$ ng generate store State --root --module app.module.ts --collection @ngrx/schematics
--> Same error as above.

So I went into node_modules/@angular/cli/package.json to look for the versions there, found 0.3.2 for both so tried:

npm install --save-dev @angular-devkit/[email protected]
npm install --save-dev @angular-devkit/[email protected]
$ ng generate store State --root --module app.module.ts --collection @ngrx/schematics
--> Still same error as above.

DevDeps after downgrading devkit/core and devkit/schematics:

  "devDependencies": {
    "@angular-devkit/core": "^0.3.2",
    "@angular-devkit/schematics": "^0.3.2",
    "@angular/cli": "~1.7.4",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@ngrx/schematics": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

After a bit of regexp searching in node_modules I think I found the Exception class used here, in @angular-devkit/core/src/exception.js but don't know where to go from here...

class FileDoesNotExistException extends BaseException {
    constructor(path) { super(`Path "${path}" does not exist.`); }
}

Edit: After some super-advanced console.log sniping, this is where the Exception is thrown in @angular-devkit/schematics/src/tree/virtual.js:

    _overwrite(path, content, action) {
        if (!this.has(path)) {
            console.log('* path: ', path);
            console.log('* action: ', action);
            throw new exception_1.FileDoesNotExistException(path);
        } else {            
            console.log('* OK path: ', path);
            console.log('* OK action: ', action);
        }
        // Update the action buffer.
        if (action) {
            this._actions.push(action);
        }
        else {
            this._actions.overwrite(path, content);
        }
        this.set(new entry_1.SimpleFileEntry(path, content));
    }
* OK path:  /src/app/app.module.ts
* OK action:  undefined
* ERR path:  /__path__/__statePath__/index.ts
* ERR action:  { id: 2,
  parent:
   { id: 1,
     parent: 0,
     kind: 'c',
     path: '/__path__/__statePath__/index.ts',
     content: <Buffer 69 6d 70 6f 72 74 20 ... > },
  kind: 'o',
  path: '/__path__/__statePath__/index.ts',
  content: <Buffer 69 6d 70 6f 72 74 20 ... > }

@funkizer @brandonroberts suggestions worked for me

@SpeedoPasanen I was having the same issue. Try generating with the command below:

ng g @ngrx/schematics:store State --root --module app.module.ts

Worked for me.

thanks duluca !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dollyshah-02-zz picture dollyshah-02-zz  路  3Comments

brandonroberts picture brandonroberts  路  3Comments

smorandi picture smorandi  路  3Comments

ghost picture ghost  路  3Comments

sandangel picture sandangel  路  3Comments