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

Babel6 not transform class definitions with Angular 5, Webpack 3.8.1 #7206

Closed
belrbeZ opened this Issue Jan 12, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@belrbeZ

belrbeZ commented Jan 12, 2018

Hello!

Why babel does not transform my classes?

I get this error only in IE11:
Syntax error main.js (24,25)

24: let ObjectTypeService _= class_ ObjectTypeService {
    constructor(config, http) {
        this.config = config;
        this.http = http;
        this.baseUrl = `${this.config.webApiBaseUrl}/configuration/objectTypes`;
    }

I try to add support of IE 11 by my app, but babel not work correctly. I had also added polyfills.ts from angular.io documentation to support IE.

Here I'll show you my .babelrc, webpack.config.js package.json, tsconfig.json.
I try to add support of IE 11 by my app, but babel not work correctly. I had also added polyfills.ts from angular.io documentation to support IE.

Here I'll show you my babelrc, webpack.config.js package.json, tsconfig.json.

Babel/Babylon Configuration (.babelrc)

babelrc

{
  "presets": [
    /*[
      "env",
      {
        "uglify":true,
        "targets":[
          "> 4%",
          "ie >= 10",
          "safari >= 8"
        ]
      }
    ]//It gives the same result*/
    "es2015", "angular2", "stage-0"
  ],
  "plugins": [
    "transform-runtime",
    "transform-decorators-legacy",
    "transform-class-properties",
    "transform-es2015-classes",
    "babel-plugin-transform-object-rest-spread",
    "syntax-object-rest-spread",
    "transform-class-constructor-call",
    "syntax-class-constructor-call"
  ]
}
webpack.config.js

module.exports = (env = {isProd: false}) => {

const config = {
    context: srcDir,

entry: {
    polyfills: './polyfills.ts',
    vendor: './vendor.ts',
    main: './main.ts',
    styles: './styles.scss'
},

...

resolve: {
  extensions: ['.js', '.ts'],

    modules: ['node_modules']
},

module: {
  loaders: [
  ],
  rules: [
      {
          test: [/\.js$/],
          include: [
              path.resolve(__dirname,'src/')
          ],
          exclude: [
              /node_modules/
          ],
          use: {
              loader: 'babel-loader'
          }
      },
    {
      test: /\.ts$/,
      include: [srcDir],
      use: env.isProd ? '@ngtools/webpack' : [
        {
          loader: 'awesome-typescript-loader',
            options: {configFileName: 'tsconfig.json'
          }
        }, 'angular2-template-loader'
      ]
    },
   .....
},

plugins: [
  ....
    new webpack.optimize.CommonsChunkPlugin({
        name: ['main', 'vendor', 'polyfills']
    }),
  ....
  new HtmlPlugin({
      template: './index.html'
  }),
 ....
],
....}
package.json

"dependencies": {

"@angular/animations": "5.1.0",
"@angular/cdk": "5.0.1",
"@angular/common": "5.1.0",
"@angular/compiler": "5.1.0",
"@angular/core": "5.1.0",
"@angular/forms": "5.1.0",
"@angular/http": "5.1.0",
"@angular/material": "5.0.1",
"@angular/platform-browser": "5.1.0",
"@angular/platform-browser-dynamic": "5.1.0",
"@angular/platform-server": "5.1.0",
"@angular/router": "5.1.0",
"angular-2-dropdown-multiselect": "1.5.4",
"bootstrap": "4.0.0-alpha.6",
"classlist.js": "1.1.20150312",
"es6-promise": "^4.2.2",
"es6-shim": "^0.35.3",
"gulp": "3.9.1",
"hammerjs": "2.0.8",
"isomorphic-fetch": "2.2.1",
"jquery": "3.2.1",
"ng2-select2": "1.0.0-beta.10",
"ngx-clipboard": "9.0.0",
"ngx-mydatepicker": "2.1.0",
"reflect-metadata": "0.1.10",
"rxjs": "5.5.5",
"select2": "4.0.5",
"sonarqube-scanner": "2.0.2",
"systemjs": "0.19.39",
"zone.js": "0.8.18"
},

"devDependencies": {

"@angular/compiler-cli": "5.1.0",
"@ngtools/webpack": "1.9.0",
"@types/angular-resource": "1.5.6",
"@types/angular-route": "1.3.2",
"@types/angular-sanitize": "1.3.3",
"@types/jasmine": "2.5.36",
"@types/node": "7.0.31",
"angular2-template-loader": "0.6.2",
"autoprefixer": "7.1.1",
"awesome-typescript-loader": "3.1.3",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-syntax-object-rest-spread": "^6.3.13",
"babel-plugin-transform-class-properties": "^6.0.2",
"babel-plugin-transform-es2015-classes": "^6.18.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.14.0",
"babel-plugin-transform-es2015-template-literals": "^6.3.13",
"babel-plugin-transform-flow-strip-types": "^6.4.0",
"babel-plugin-transform-object-assign": "^6.3.13",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-class-constructor-call": "^6.0.2",
"babel-plugin-syntax-class-constructor-call": "^6.18.0",
"babel-polyfill": "^6.26.0",
"babel-preset-angular2": "^0.0.2",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "6.16.0",
"babel-preset-es2015-native-modules": "^6.9.4",
"babel-preset-es2015-rollup": "1.2.0",
"babel-preset-stage-0": "^6.0.15",
"babel-register": "^6.26.0",
"concurrently": "3.0.0",
"codelyzer": "3.0.1",
"copy-webpack-plugin": "4.0.1",
"core-js": "2.5.1",
"css-loader": "0.28.7",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "0.11.2",
"html-loader": "0.4.5",
"html-webpack-plugin": "2.30.1",
"intl": "1.2.5",
"jasmine-core": "2.6.3",
"karma": "1.7.0",
"karma-chrome-launcher": "2.1.1",
"karma-coverage-istanbul-reporter": "1.3.0",
"karma-firefox-launcher": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-webpack": "2.0.3",
"node-sass": "4.6.1",
"postcss-loader": "2.0.6",
"raw-loader": "0.5.1",
"sass-loader": "6.0.6",
"style-loader": "0.19.0",
"stylelint": "7.11.1",
"stylelint-config-standard": "16.0.0",
"tslint": "5.4.3",
"typedoc": "0.7.1",
"typescript": "2.5.3",
"uglifyjs-webpack-plugin": "1.0.1",
"web-animations-js": "2.3.1",
"webpack": "^3.8.1",
"webpack-chunk-hash": "^0.4.0",
"webpack-dev-server": "2.9.4",
"webpack-merge": "3.0.0"
}
}
tsconfig.json

{
"compilerOptions": {

"alwaysStrict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": false,
"sourceMap": true,
"skipLibCheck": true,
"strictNullChecks": true,
"target": "es5",
"typeRoots": [
  "./node_modules/@types"
],
"lib": ["es2015", "dom"] /* , "es2015.promise"*/
},
"exclude": [
    "node_modules"
]
...
}

Expected Behavior

As I understand, babel should transform it in something else of es5-version.

Current Behavior

There are class definitions in main.js after transformations.

Possible Solution

Maybe my configuration is not right?

Context

IE11 still fails with syntax error on '...= class {...'.

@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Jan 12, 2018

Collaborator

Hey @belrbeZ! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Collaborator

babel-bot commented Jan 12, 2018

Hey @belrbeZ! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@belrbeZ

This comment has been minimized.

Show comment
Hide comment
@belrbeZ

belrbeZ Jan 15, 2018

Thank you!

The problem was solved by changing the versions of the dependencies a package.json file.

belrbeZ commented Jan 15, 2018

Thank you!

The problem was solved by changing the versions of the dependencies a package.json file.

@belrbeZ belrbeZ closed this Jan 15, 2018

@lock lock bot added the outdated label May 3, 2018

@lock lock bot locked as resolved and limited conversation to collaborators May 3, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.