question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng serve doesn't work with linked module

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [x] bug report
- [ ] feature request

Versions.

@angular/cli: 1.2.6 node: 6.11.1 os: win32 x64 @angular/animations: 4.3.3 @angular/common: 4.3.3 @angular/compiler: 4.3.3 @angular/core: 4.3.3 @angular/forms: 4.3.3 @angular/http: 4.3.3 @angular/platform-browser: 4.3.3 @angular/platform-browser-dynamic: 4.3.3 @angular/router: 4.3.3 @angular/cli: 1.2.6 @angular/compiler-cli: 4.3.3 @angular/language-service: 4.3.3

Repro steps.

Create a node module locally and link it with npm link. Go to your project generated with @angular/cli and link this module: npm link ngx-my-module. Use your module in your project. For instance:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MyModule } from 'ngx-my-module';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AnalyticsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Then run ng serve

The log given by the failure.

λ ng serve
Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at createSourceFile (my-module\node_modules\typescript\lib\typescript.js:15457:109)
    at parseSourceFileWorker (my-module\node_modules\typescript\lib\typescript.js:15389:26)
    at Object.parseSourceFile (my-module\node_modules\typescript\lib\typescript.js:15338:26)
    at Object.createSourceFile (my-module\node_modules\typescript\lib\typescript.js:15192:29)
    at WebpackCompilerHost.getSourceFile (my-module\node_modules\@ngtools\webpack\src\compiler_host.js:239:27)
    at findSourceFile (my-module\node_modules\typescript\lib\typescript.js:67909:29)
    at processSourceFile (my-module\node_modules\typescript\lib\typescript.js:67840:27)
    at my-module\node_modules\typescript\lib\typescript.js:67950:17
    at Object.forEach (my-module\node_modules\typescript\lib\typescript.js:1449:30)
    at processReferencedFiles (my-module\node_modules\typescript\lib\typescript.js:67948:16)
    at findSourceFile (my-module\node_modules\typescript\lib\typescript.js:67933:21)
    at processImportedModules (my-module\node_modules\typescript\lib\typescript.js:68056:25)
    at findSourceFile (my-module\node_modules\typescript\lib\typescript.js:67937:17)
    at processImportedModules (my-module\node_modules\typescript\lib\typescript.js:68056:25)
    at findSourceFile (my-module\node_modules\typescript\lib\typescript.js:67937:17)
    at processImportedModules (my-module\node_modules\typescript\lib\typescript.js:68056:25)

Mention any other details that might be useful.

I used generator-ngx-library to generate my node module project. It uses @angular/cli in a demo app.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hieuxlucommented, Aug 11, 2017

This have been discussed many times as in https://github.com/angular/angular-cli/issues/6228#issuecomment-301024884. I believe the correct way to do this is to use tsconfig.json paths property, instead of linking it as a module. You can see paths it in @angular/cli tsconfig.json as well.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 7, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'ng serve' does not work after a double install - Stack Overflow
The key is to have both global and local Angular-cli versions the same. Let's say we want to fixate it to eg. 1.0.0-beta.15...
Read more >
ng serve - Angular
Option Description Value Type Default Value ‑‑hmr Enable hot module replacement. boolean false ‑‑host Host to listen on. string localhost ‑‑open Opens the url in default...
Read more >
ng: command not found (Angular) error [Solved] | bobbyhadz
To solve the error "ng: command not found", install the angular cli package globally by running npm install -g @angular/cli@latest and restart your...
Read more >
@angular/cli - npm
Start using @angular/cli in your project by running `npm i @angular/cli`. ... If you wish to collaborate, check out our issue list.
Read more >
ng serve changes not detected when use "safe write" enabled
issue link in the angular/cli github repository https://github.com/angular/angular-cli/issues/2389 ... 10% building modules 0/1 modules 1 active .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found