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

Transpile to ES5 not working for imported modules #11892

Closed
mengzhen94 opened this issue Aug 14, 2018 · 2 comments
Closed

Transpile to ES5 not working for imported modules #11892

mengzhen94 opened this issue Aug 14, 2018 · 2 comments

Comments

@mengzhen94
Copy link

I am importing js classes as modules to other js files and import them to my angular 5 ts project like this:

if (typeof module !== 'undefined') {
  var CPE = {};
  CPE.a1 = require('./a1');
}

CPE.a2 = class a2 extends a1 {}
if (typeof module !== 'undefined') {
  var CPE = {};
  CPE.a3 = require('../a/a3.js');
  CPE.a4 = require('../a/a4.js');
}

CPE.a5 = class Curve{
  constructor (params = {}) {
    params.className = 'a5';

    super(params);

    this.modifiers = {
      a3: new CPE.a3(this),
      a4: new CPE.a4(this)
    };
  }
 ....

In ts file:

import * as CPE from '../../../../../app/aa/a/a1';

When ng build --prod and transpile to ES5, some of js class are still 'class', not transpiled at all. Also weird thing is each time the files not transpiled properly are not same.
Here is the file main.XXX.bundle.js after build:

if (typeof module !== 'undefined') {
  var CPE = {};
  CPE.a3 = require('../a/a3.js');
  CPE.a4 = require('../a/a4.js');
}

CPE.a5 = class Curve{
  constructor (params = {}) {
    params.className = 'a5';

    super(params);

    this.modifiers = {
      a3: new CPE.a3(this),
      a4: new CPE.a4(this)
    };
  }
 ....

it is literally the original js class, not transpiled at all.

Versions

tsconfig,json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "baseUrl": "./src/",
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "types": [
      "underscore"
    ],
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "plugins": [
      { "name": "tslint-language-service"}
    ]
  }
}

package.json

  "devDependencies": {
    "@angular/cli": "1.7.4",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
...

The log given by the failure

Not build errors. But the 'class' keyword fails on IE11

Is there anyone has clue what is happening and how to fix it? Thanks.

@clydin
Copy link
Member

clydin commented Aug 15, 2018

The CLI does not transpile Javascript code. Third-party code is expected to be in the appropriate format.
For project files that are javascript and imported in TypeScript files, the allowJs option may allow the javascript files to be processed by the TypeScript compiler. Please note that this is untested and not officially supported.

@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.
Projects
None yet
Development

No branches or pull requests

3 participants