Skip to content

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

@yfain

Description

@yfain

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions