Skip to content

Decorators and babel polyfills #9602

@pldilley

Description

@pldilley

Bug Report

It seems that the current babel implementation of decorators relies on using Symbol. However, even with babel polyfills enabled, in this instance Symbol is not polyfilled and an error is thrown in IE11.

Current Behavior
IE11 throws an error when using babelled decorators: 'Symbol' is undefined

Input Code
Using a decorator anywhere in the code

Expected behavior/code
The Symbol polyfill perhaps should be imported automatically

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": [
    ["@babel/preset-env", {
      "targets": {
        "browsers": [
          "ie 11",
          "last 2 versions",
          "> 1%"
        ]
      },
      "modules": false,
      "useBuiltIns": "usage"
    }]
  ],
  "plugins": [
    ["@babel/plugin-proposal-class-properties"],
    ["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": false }],
    ....

Environment

  • Browser: IE11 (and probably any IE)
  • Babel version(s): v7.2.0
  • Node/npm version: node 10.3.0/npm 6.1.0
  • OS: OSX 10.14.3
  • Monorepo: ?
  • How you are using Babel: ?

Possible Solution
Currently you can get round it by simply mentioning Symbol at the top of your project

Metadata

Metadata

Assignees

No one assigned

    Labels

    Spec: DecoratorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions