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

tslib helpers replacement causes build failure "Module parse failed: 'import' and 'export' may only appear at the top level" #12568

Closed
MrAntix opened this issue Oct 12, 2018 · 3 comments · Fixed by #12586
Labels
Milestone

Comments

@MrAntix
Copy link

MrAntix commented Oct 12, 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
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

npm 6.4.1

Node: 10.12.0
OS: win32 x64
Angular: 6.1.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.8.5
@angular-devkit/build-angular 0.8.5
@angular-devkit/build-optimizer 0.8.5
@angular-devkit/build-webpack 0.8.5
@angular-devkit/core 0.8.4
@angular-devkit/schematics 0.8.4
@angular/cli 6.2.4
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.2.5
@schematics/angular 0.8.4
@schematics/update 0.8.4
ng-packagr 4.3.0
rxjs 6.3.3
typescript 2.9.2
webpack 4.20.2

Repro steps

using a library with the following code

/*! Built with http://stenciljs.com */
export default function appGlobal(namespace, Context, window, document, resourcesUrl, hydratedCssClass) {(function(resourcesUrl){
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();

optimizer replaces __extends in the wrong place, the result is

Module parse failed: 'import' and 'export' may only appear at the top level (3:8)
You may need an appropriate loader to handle this file type.
| export default function appGlobal(namespace, Context, window, document, resourcesUrl, hydratedCssClass) {
|     (function (resourcesUrl) {
>         import { __extends } from "tslib";
|         /*!

Desired functionality

Can you put the imports uniquely at the top of the file?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Oct 12, 2018

I have an idea or two how to solve this. That said, the above input looks rather strange, as TypeScript compiler doesn't emit helpers inside methods but rather always puts them in top level.

@MrAntix
Copy link
Author

MrAntix commented Oct 29, 2018

works on 7.0.1 - thanks

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

Successfully merging a pull request may close this issue.

2 participants