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

After running ng add @nguniversal/express-engine --clientProject [PROJECT_NAME] my main.ts is no longer valid due to import statements being moved within the callback. #13042

Closed
Nysosis opened this issue Nov 23, 2018 · 3 comments · Fixed by #13052
Milestone

Comments

@Nysosis
Copy link

Nysosis commented Nov 23, 2018

Bug Report or Feature Request (mark with an x)

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

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [x] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Angular CLI: 7.0.6
Node: 10.13.0
OS: win32 x64
Angular: 7.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.10.6
@angular-devkit/build-angular 0.10.6
@angular-devkit/build-optimizer 0.10.6
@angular-devkit/build-webpack 0.10.6
@angular-devkit/core 7.0.6
@angular-devkit/schematics 7.0.6
@angular/cli 7.0.6
@angular/platform-server 7.1.0
@ngtools/webpack 7.0.6
@schematics/angular 7.0.6
@schematics/update 0.10.6
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1

Repro steps

Following the Universal tutorial on https://angular.io/guide/universal for my app, and it runs ng add @nguniversal/express-engine --clientProject angular.io-example, running the same for my angular 7 app results in the following main.ts:

document.addEventListener('DOMContentLoaded', () => {
  import { enableProdMode } from '@angular/core';
  import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
  import { AppModule } from './app/app.module';
  import { environment } from './environments/environment';
  import { hmrBootstrap } from './hmr';

  if (environment.production) {
    enableProdMode();
  }

  const bootstrap = () => platformBrowserDynamic().bootstrapModule(AppModule);

  if (environment.hmr) {
    if ((<any>module)['hot']) {
      hmrBootstrap(module, bootstrap);
    } else {
      console.error('HMR is not enabled for webpack-dev-server!');
      console.log('Are you using the --hmr flag for ng serve?');
    }
  } else {
    bootstrap().catch(err => console.log(err));
  }

});

However I'm getting ts errors due to ts not being happy with the import statements not being the first thing in the file.

@clydin
Copy link
Member

clydin commented Nov 24, 2018

If the changes are being done by the package being added, please open an issue with the package directory.

@clydin clydin closed this as completed Nov 24, 2018
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Nov 25, 2018

The package is actually using the universal schematic https://github.com/angular/universal/blob/fd87d0db6d6beb69a7e7f8302bef4464f66bea58/modules/express-engine/schematics/install/index.ts#L171 and the failing code is

function wrapBootstrapCall(options: UniversalOptions): Rule {

The same issue should be reproducible if you do ng generate universal as well.

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

Successfully merging a pull request may close this issue.

3 participants