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

ASP.NET Core 2.0 + Angular 5 App with Kendo components failed when published to production with SSR and AoT enabled #1210

Closed
lankaapura opened this issue Jan 12, 2018 · 7 comments
Assignees
Labels

Comments

@lankaapura
Copy link

lankaapura commented Jan 12, 2018

I'm submitting a...

  • Bug report

Current behavior

We have upgraded our existing angular 4.x.x project to angular 5.x. As a part of that, we have migrated to latest Asp.net project template too (which is based on angular CLI).

even though everything works fine in the development environment, @progress packages giving 'Unexpected token import' error when it published to production.

2018-01-12 13:21:58.697 +05:30 [ERR] HTTP GET /index.html responded 500 in 3295.7207893842437 ms
Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Prerendering failed because of error: C:\Dev\IIS\XXX\ClientApp\node_modules\@progress\kendo-angular-resize-sensor\dist\es\resize-sensor.component.js:1
(function (exports, require, module, __filename, __dirname) { import { Component, ElementRef, EventEmitter, Input, Output, ViewChild, NgZone, Renderer2 } from '@angular/core';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.ayiD (C:\Dev\IIS\XXX\ClientApp\dist-server\main.bundle.js:1:542921)
Current directory is: C:\Dev\IIS\XXX

   at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.<InvokeExportAsync>d__7`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.<InvokeExportAsync>d__13`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.<InvokeExportWithPossibleRetryAsync>d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.<InvokeExportWithPossibleRetryAsync>d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.AspNetCore.Builder.SpaPrerenderingExtensions.<>c__DisplayClass0_0.<<UseSpaPrerendering>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at XXX.Core.ErrorHandleAndLogMiddleware.<Invoke>d__4.MoveNext()

Workaround

Follow instructions here and compile js files into es2015

    "compile_telerik_node_modules": "node node_modules/babel-cli/bin/babel.js node_modules/@progress -d node_modules/@progress --presets es2015",
    "postinstall": "npm run compile_telerik_node_modules",

Environment

Package versions:

+-- @angular-devkit/schematics@0.0.42
+-- @angular/animations@5.2.0
+-- @angular/cli@1.6.3
+-- @angular/common@5.2.0
+-- @angular/compiler@5.2.0
+-- @angular/compiler-cli@5.2.0
+-- @angular/core@5.2.0
+-- @angular/forms@5.2.0
+-- @angular/http@5.2.0
+-- @angular/language-service@5.2.0
+-- @angular/platform-browser@5.2.0
+-- @angular/platform-browser-dynamic@5.2.0
+-- @angular/platform-server@5.2.0
+-- @angular/router@5.2.0
+-- @nguniversal/module-map-ngfactory-loader@5.0.0-beta.5
+-- @ngx-cache/core@5.0.0
+-- @ngx-cache/fs-storage@5.0.0
+-- @ngx-cache/platform-browser@5.0.0
+-- @ngx-cache/platform-server@5.0.0
+-- @progress/kendo-angular-buttons@2.0.0
+-- @progress/kendo-angular-dateinputs@1.4.3
+-- @progress/kendo-angular-dialog@1.3.0
+-- @progress/kendo-angular-dropdowns@1.6.0
+-- @progress/kendo-angular-excel-export@1.0.5
+-- @progress/kendo-angular-grid@1.6.5
+-- @progress/kendo-angular-inputs@1.4.2
+-- @progress/kendo-angular-intl@1.3.0
+-- @progress/kendo-angular-l10n@1.0.5
+-- @progress/kendo-angular-layout@1.2.0
+-- @progress/kendo-angular-popup@1.3.1
+-- @progress/kendo-angular-resize-sensor@2.0.1
+-- @progress/kendo-data-query@1.1.2
+-- @progress/kendo-drawing@1.4.0
+-- @progress/kendo-theme-default@2.46.0
+-- @types/jasmine@2.8.3
+-- @types/jasminewd2@2.0.3
+-- @types/node@9.3.0
+-- angular-oauth2-oidc@3.1.4
+-- aspnet-prerendering@3.0.1
+-- babel-cli@6.26.0
+-- babel-preset-env@1.6.1
+-- babel-preset-es2015@6.24.1
+-- bootstrap@3.3.7
+-- codelyzer@4.0.2
+-- core-js@2.5.3
+-- jasmine-core@2.8.0
+-- jasmine-spec-reporter@4.2.1
+-- karma@2.0.0
+-- karma-chrome-launcher@2.2.0
+-- karma-cli@1.0.1
+-- karma-coverage-istanbul-reporter@1.3.3
+-- karma-jasmine@1.1.1
+-- karma-jasmine-html-reporter@0.2.2
+-- ng-block-ui@0.9.3
+-- protractor@5.2.2
+-- rxjs@5.5.6
+-- ts-node@4.1.0
+-- tslint@5.9.1
+-- typescript@2.4.2
`-- zone.js@0.8.20
@tsvetomir
Copy link
Member

It looks like the SSR implementation uses the "module" entry point, but attempts to execute the code in NodeJS.

This will not work unless the application code is first bundled through Webpack or Rollup. Babel can also be used, but technically the code doesn't need transpilation, just different module syntax.

I'm not sure what we could do to rectify this. The packages already have a "main" entry point with the correct module type for NodeJS, as per the CommonJS specification. This code doesn't seem to be used in this case.

@lankaapura
Copy link
Author

Thanks for the explanation. Is there any way to force Angular CLI to use correct module entry point?

@tsvetomir
Copy link
Member

Updates

Workaround

  • Replace "dist/es/" with "dist/npm/" in "ClientApp\dist-server\main.bundle.js"

@tsvetomir tsvetomir self-assigned this Feb 5, 2018
@lankaapura
Copy link
Author

Thanks @tsvetomir for the investigation. Based on comments, it seems that this related to how we publish the NPM package. See the explanations by Toxicable. He has shared this doc which will be helpful to fix the issue.

@tsvetomir
Copy link
Member

Thanks for sharing 👍

The most likely reason why this is not an issue with the @angular packages is that they use flat
modules. They provide other benefits like improved built times too.

We would've considered them as a possible solution, but there is some controversy on whether they're a good choice going forward.

In any case, our current packaging should also work provided the SSR implementation picks up the right entry point.

@tsvetomir
Copy link
Member

Managed to solve this by changing the package structure. All latest package versions include the fix.

@lankaapura
Copy link
Author

Awesome! Thanks @tsvetomir 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants