Skip to content

Angular Universal build prerender error #195

Open
@kmturley

Description

@kmturley
  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • Do you want to request a feature or report a bug?
    Bug with your library and Angular Universal build prerender functionality

  • What is the current behavior?
    When you run the command:
    npm run build:prerender

it runs:
"generate:prerender": "cd dist && node prerender",

Then fails with the error:

(function (exports, require, module, __filename, __dirname) { import { NgModule } 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:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.ngx-drag-scroll/lib/ngx-drag-scroll.module (example-site/dist/server/main.js:1927:18)
  • provide the steps to reproduce

Either use my demo repo:
https://github.com/kmturley/universal-starter

OR

  1. Duplicate the Angular Universal starter project from:
    https://github.com/angular/universal-starter

  2. Add your library, following install instructions:
    https://github.com/bfwg/ngx-drag-scroll

  3. Run the Angular build command to see the error:
    npm run build:prerender

  • What is the expected behavior?
    No error, and to continue building.

  • What is the motivation / use case for changing the behavior?
    Otherwise your plugin cannot be used with Angular Universal, which means no static site generation :(

  • Please tell us about your environment:

    • MacOS 10.13.6
    • node 8.9.1
    • ng-cli 6.0.0 and tested with 7.1.4
    • angular 6.0.0 and tested with 7.1.4
    • nguniversal 6.0.0 and tested with 7.0.2
  • Other information

Looks like other people have had similar problems with Angular Universal and third-party libraries such as yours:
angular/angular-cli#7200 (comment)

They say the third-party libraries aren't being built correctly, which means Angular Universal fails:
angular/angular-cli#7200 (comment)

for example they suggest adding to your package.json

"module": "./quickstart-lib.es5.js",
"es2015": "./quickstart-lib.js",
"typings": "./quickstart-lib.d.ts",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions