Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng serve doesn't work with linked module #7332

Closed
sichida opened this issue Aug 10, 2017 · 8 comments
Closed

ng serve doesn't work with linked module #7332

sichida opened this issue Aug 10, 2017 · 8 comments
Assignees
Labels
P5 The team acknowledges the request but does not plan to address it, it remains open for discussion severity2: inconvenient

Comments

@sichida
Copy link

sichida commented Aug 10, 2017

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.

@hieuxlu
Copy link

hieuxlu commented Aug 11, 2017

This have been discussed many times as in #6228 (comment). 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.

@ebtc
Copy link

ebtc commented Aug 16, 2017

I am having a similar issue since the cli >1.3 version. I did check the story on linked modules and - to my understanding - I am doing what is being asked there.

Picture: I am developing an App for the web and iOS/Android that uses a common set of core modules (mainly NGRX functionality and interfaces). Those core files are compiled into a module that gets linked to the web/ mobile app.

I compile the lib with ngc and link it via yarn link.
In my web app's tsconfig.json I have the path section as described in the story, which worked with the CLI until the recent 1.3 release.

I am a little confused as to what is going here. I have also looked at the example repo that @filipesilva created. It seems overkill in my case (until now it worked well without all that).

The core module is here.

Any ideas? I would love to move along with cli and not be pinned to 1.2.4 ;)

@hieuxlu
Copy link

hieuxlu commented Aug 16, 2017

@ebtc Okay. This is another new issue with v1.3.0. You should fix the version to 1.3.0-rc.5 to see new features such as named-chunk (one of my favorite), while avoid the issue with tsconfig paths. For more discussion on this, read #7341

@ebtc
Copy link

ebtc commented Aug 16, 2017

just to mention the error message:

Uncaught Error: Unexpected value 'MHCoreModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

This appears in the browser itself (console), while the CLI output is fine.

If I don't use commonjs as module for the core module, then al hell breaks lose :)

@sichida
Copy link
Author

sichida commented Aug 16, 2017

Thanks @hieuxlu for your reply.
I've tried to remove my dependency from package.json and put it in peerDependencies instead and combine it with a link within my tsconfig.json as you have mentioned but I am still getting the same error.
Any ideas?
Thanks

@sichida
Copy link
Author

sichida commented Aug 17, 2017

More information that may be helpful:
I am using a definition.d.ts file to add some declaration to Window interface. If I remove this reference it is working fine.
I believe the problem does not come from linked module but from the definition file used within the project.
Make sense for you?

@Brocco Brocco added P5 The team acknowledges the request but does not plan to address it, it remains open for discussion severity2: inconvenient labels Aug 18, 2017
@filipesilva
Copy link
Contributor

Closing as a duplicate of #6228 (comment) and #7341, as @hieuxlu mentioned. Please see those issues for the recommended approaches.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P5 The team acknowledges the request but does not plan to address it, it remains open for discussion severity2: inconvenient
Projects
None yet
Development

No branches or pull requests

5 participants