Skip to content

Can't have the module and component's code inside main.ts #3744

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

Closed
yfain opened this issue Dec 26, 2016 · 4 comments
Closed

Can't have the module and component's code inside main.ts #3744

yfain opened this issue Dec 26, 2016 · 4 comments

Comments

@yfain
Copy link

yfain commented Dec 26, 2016

I've generated the project using beta.24. It works fine. Now I want to have more than one version of the main.ts for demo purposes, which worked fine in beta.21. For example, I had a number of main files here https://github.com/Farata/angular2typescript/tree/master/chapter3/extras/cli_version/router_samples/src and was able to switch between them by changing the main property in angular-cli.json.

I tried to do the same with beta.24, but getting this error during ng serve:

Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
    at Object.resolveEntryModuleFromMain (/Users/yfain11/Documents/Farata/_Training/courseware/angular2/handouts/12-hr-intro/unit1/w3/node_modules/@ngtools/webpack/src/entry_resolver.js:131:11)
    at AotPlugin._setupOptions (/Users/yfain11/Documents/Farata/_Training/courseware/angular2/handouts/12-hr-intro/unit1/w3/node_modules/@ngtools/webpack/src/plugin.js:158:54)
    at new AotPlugin (/Users/yfain11/Documents/Farata/_Training/courseware/angular2/handouts/12-hr-intro/unit1/w3/node_modules/@ngtools/webpack/src/plugin.js:17:14)
    at Object.exports.getWebpackNonAotConfigPartial (/Users/yfain11/Documents/Farata/_Training/courseware/angular2/handouts/12-hr-intro/unit1/w3/node_modules/angular-cli/models/webpack-build-typescript.js:20:13)
    at new NgCliWebpackConfig (/Users/yfain11/Documents/Farata/_Training/courseware/angular2/handouts/12-hr-intro/unit1/w3/node_modules/angular-cli/models/webpack-config.js:26:42)
    at Class.run (/Users/yfain11/Documents/Farata/_Training/courseware/angular2/handouts/12-hr-intro/unit1/w3/node_modules/angular-cli/tasks/serve-webpack.js:20:22)
    at /Users/yfain11/Documents/Farata/_Training/courseware/angular2/handouts/12-hr-intro/unit1/w3/node_modules/angular-cli/commands/serve.js:108:26
    at process._tickCallback (internal/process/next_tick.js:103:7)

The only thing I can think of that for some reason ng serve can't find the bootstrap code if the module and component are inlined in the main file. Here's the code that I tried to paste into main.ts, that generates the above exception:

import './polyfills.ts';
import {Component} from '@angular/core';
import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

@Component({
    selector: 'one-way-binding',
    template:`
      <h1>{{name}}</h1>
      
      <button (click)="changeName()">Change name</button>
    `
    })
class AppComponent{
    name:string = "Mary Smith";

    changeName(){
        this.name="Bill Smart";
    }
}

@NgModule({
    imports:      [ BrowserModule],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
export class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);
@PG2000
Copy link

PG2000 commented Dec 27, 2016

@yfain
I think its the same like #3540
Would you be able to checkout the latest master of angular-cli and try it again ?

You can find the changes in master => #3708

@yfain
Copy link
Author

yfain commented Dec 27, 2016

@PG2000

Tried with the latest CLI from master. There error is still there.

@filipesilva
Copy link
Contributor

Dupe of #3540, same root cause.

@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants