Angular-cli: Cannot create module. TypeError: Cannot read property 'replace' of null

Created on 12 May 2017  路  8Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.


@angular/cli: 1.0.3
node: 7.8.0
os: darwin x64
@angular/animations: 4.1.2
@angular/common: 4.1.2
@angular/compiler: 4.1.2
@angular/core: 4.1.2
@angular/forms: 4.1.2
@angular/http: 4.1.2
@angular/platform-browser: 4.1.2
@angular/platform-browser-dynamic: 4.1.2
@angular/router: 4.1.2
@angular/cli: 1.0.3
@angular/compiler-cli: 4.1.2

Repro steps.


Command:

ng g module anything

The log given by the failure.

installing module
Cannot read property 'replace' of null
TypeError: Cannot read property 'replace' of null
    at decamelize (/***/node_modules/ember-cli-string-utils/index.js:25:13)
    at Object.dasherize (/***/node_modules/ember-cli-string-utils/index.js:50:11)
    at Class.<anonymous> (/***/node_modules/@angular/cli/ember-cli/lib/models/blueprint.js:861:42)
    at tryCatch (/***/node_modules/rsvp/dist/rsvp.js:539:12)
    at invokeCallback (/***/node_modules/rsvp/dist/rsvp.js:554:13)
    at /***/node_modules/rsvp/dist/rsvp.js:629:16
    at flush (/***/node_modules/rsvp/dist/rsvp.js:2414:5)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Desired functionality.

Should create a module

Mention any other details that might be useful.

This happens for already a couple of days. Would really appreciate any hints on solving this. Same happens when I try to create a component.

easy (hours) low bufix

Most helpful comment

this is comment maybe helpful for you ,solution is easy

{ path:'discussion',
loadChildren:'app/discussion/discussion.module#DiscussionModule'
}

actually in loadChildren if we given wrong path of discussion.module ,becoz of this """"we get Cannot read property 'replace' of null""""

if we give exact path of module in loadchildren problem will be fixed ...

thank you !!

All 8 comments

@smnbbrv does this happen with a clean project? can you share your .angular-cli.json file

hi @deebloo

thank you for response.

When I try it with a brand new module it works fine.

This is the current configuration:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "blablaproject"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "ci/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": "app",
      "styles": [
        "scss/style.scss",
        "../node_modules/ng2-toastr/bundles/ng2-toastr.min.css",
        "../node_modules/simple-line-icons/css/simple-line-icons.css"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "prefixInterfaces": false
  }
}

I tried to update (and updated) angular-cli in both projects, and global scope according to the manual, cleaned node_modules more than once etc.

@deebloo Are you running the command at the root of the project or any other folder? From the above error, it seems like it's not able to find the correct project name and trying to replace it.

@sumitarora you are so much right, Sir! Some time ago I've removed the "name" property in the package.json because I thought it is useless because of "private": true property.

Returning it back fixes the issue. Thank you very much!

However, why is the package.json name used to generate the modules? It is a bit confusing for me now.

@smnbbrv Ok I investigated it further it's due to old code from ember-cli specifically https://github.com/angular/angular-cli/blob/master/packages/@angular/cli/ember-cli/lib/models/project.js#L481 which reads package.json and gets project name from there.

In my case, it was due to a bad path passed to loadChildren

import {Route} from '@angular/router';
export const routes: Route[] = [
  { path: 'feature', loadChildren: './incorrect/path/to/module/the-module.module#FeatureModule' }
];

this is comment maybe helpful for you ,solution is easy

{ path:'discussion',
loadChildren:'app/discussion/discussion.module#DiscussionModule'
}

actually in loadChildren if we given wrong path of discussion.module ,becoz of this """"we get Cannot read property 'replace' of null""""

if we give exact path of module in loadchildren problem will be fixed ...

thank you !!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings