angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

@ngtools/webpack components path problem

Open GeorgeKnap opened this issue 9 years ago • 3 comments

Bug Report or Feature Request (mark with an x)

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

Versions.

Win 10 x64 node v6.10.0

  "@angular/common": "4.0.1",
    "@angular/compiler": "4.0.1",
    "@angular/compiler-cli": "4.0.1",
    "@angular/core": "4.0.1",
    "@angular/http": "4.0.1",
    "@angular/platform-browser": "4.0.1",
    "@angular/platform-browser-dynamic": "4.0.1",
   "@ngtools/webpack": "1.3.0",
    "typescript": "2.2.2",
    "webpack": "2.3.3",

Repro steps.

@ngtools/webpack cannot find any component which is nested in root app folder's directories

in tsconfig entryModule is declared:

"angularCompilerOptions": {
    "entryModule": "app/app.module#AppModule"
  }

in app module an app.component.ts is imported from app/layout/scripts

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

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

@ngtools/webpack throws an error for any component which is not in root app folder. the log indicates it is searching for the component in it's parent folder. However if you put app.component next to app.module in app folder, the AOT compiles without problem.

The log given by the failure.

ERROR in ENOENT: no such file or directory, open 'C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\layout\app.component'
ERROR in ./app/main.ts
Module not found: Error: Can't resolve './app.module.ngfactory' in 'C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app'
resolve './app.module.ngfactory' in 'C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app'
  using description file: C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\package.json (relative path: ./app)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\package.json (relative path: ./app)
    using description file: C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\package.json (relative path: ./app/app.module.ngfactory)
      as directory
        C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory doesn't exist
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory.js doesn't exist
[C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory]
[C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory]
[C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory.ts]
[C:\Users\george\Source\Repos\ag-web-tempate\Angular.Template\Angular.Template.Web\app\app.module.ngfactory.js]

Desired functionality.

no errors. AOT compiles.

Mention any other details that might be useful.

GeorgeKnap avatar Apr 04 '17 14:04 GeorgeKnap

easy solution found myself. My @Component decorator was missing file extensions for template url and styles urls

@Component({
    selector: 'my-app',
    templateUrl: './app-layout.component.html',
    styleUrls: ['./app-layout.component.scss'],
    providers: [Title]
})

GeorgeKnap avatar Apr 04 '17 15:04 GeorgeKnap

Hi @GeorgeKnap,

I also stumbled upon the same issue, fixed it referring to your answer above!

Although, I am kinda stuck with one more issue. Since, the templateUrl or styleUrls have to just a path string or array of path strings respectively.

I have one code base supporting mobile and desktop platforms(app design isn't responsive to make one single build :( )

So in @Component decorator, for JIT I have to refer it as require(`home.${DEVICE}.component.html`), where DEVICE is a global defined in DefinePlugin of webpack.

This works fine.

Now when trying to implement AoT, one requirement is not to use require for templateUrl or stylesUrl.

Did you came across this kind of problem, if so can you show me how to set the path dynamically based on the process env. Is there any way I can still achieve two different platform AoT builds for a given component.

Any help/suggestion is welcomed, thanks!

@StephenFluin @gdi2290

harshes53 avatar May 09 '17 03:05 harshes53

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.