Parcel: Parcel does not add polyfill for Object.assign when using @babel/preset-env with useBuiltIns: 'usage'

Created on 7 Nov 2018  路  10Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

I was trying to use Parcel together with @babel/preset-env to create a bundle to run on ie 11. In my source code I had a call to Object.assign. After build the code fails running on ie with the following mesage Object doesn't support property or method 'assign'.

I have created a repo for reproducing the bug here: https://github.com/slowselfip/object-assign-ie11-polyfill-parcel

馃帥 Configuration (.babelrc, package.json, cli command)

.babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "debug": true,
        "targets": {
          "ie": "11"
        },
        "useBuiltIns": "usage"
      }
    ]
  ]
}

package.json

{
  "name": "example",
  "version": "1.0.0",
  "description": "Object assign polyfill example",
  "main": "./src/index.html",
  "scripts": {
    "build:webpack": "npm run clean && webpack --mode production",
    "build:parcel": "npm run clean && parcel build $npm_package_main",
    "clean": "rimraf dist/"
  },
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.1.2",
    "@babel/preset-env": "^7.1.5",
    "babel-loader": "^8.0.4",
    "html-webpack-plugin": "^3.2.0",
    "parcel-bundler": "^1.10.3",
    "rimraf": "^2.6.2",
    "webpack": "^4.25.1",
    "webpack-cli": "^3.1.2"
  }
}

馃 Expected Behavior

I expect it to run on ie 11 with a polyfilled Object.assign.

馃槸 Current Behavior

Code fails running on ie with the following mesage Object doesn't support property or method 'assign'

馃拋 Possible Solution

No idea, sorry.

馃敠 Context

For convenience It would be nice to be able to rely on the useBuiltIn without the need of manually adding polyfills. Also, my hopes is that this helps in fixing the bug.

馃捇 Code Sample

https://github.com/slowselfip/object-assign-ie11-polyfill-parcel

馃實 Your Environment

Mac

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | ^1.10.3
| Node | v10.10.0
| npm/Yarn | 6.4.1
| Operating System | MacOS High Sierra 10.13.6

Good First Issue Bug Stale

Most helpful comment

I'm having the same issue, and it looks like regardless of what you set in the .babelrc, it is being changed to 'entry', here:
https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/transforms/babel/env.js#L56

I tried changing that line from 'entry' to 'usage', and it worked. It might need a PR to make this actually respect the configuration...

All 10 comments

Some debug information:

When only processed with babel, npx babel src/index.js the output contains the line require("core-js/modules/es6.object.assign"); but in the Parcel bundle that module is not present.
If that line is added explicitly to the source file the module will be present in the bundle.

this seems related to #2304, the bundler doesn't seem to be applying the configuration in a recursive / deep manner

I'm having the same issue, and it looks like regardless of what you set in the .babelrc, it is being changed to 'entry', here:
https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/transforms/babel/env.js#L56

I tried changing that line from 'entry' to 'usage', and it worked. It might need a PR to make this actually respect the configuration...

nice catch @tjwlucas it seems that a lot of stuff are hardcoded irrespective of babelrc

Sounds like this will be solved in Parcel 2 by #2350

indeed, it looks like it will fix those dangling issues with configs being ignored / overridden

what will be the workaround for 1.11.0?

@mallim there's none, you need to fork the project, fix the code, then use your fork git address as the "version" field in npm (did this with two ES7+ projects)

use [email protected] stable version

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medhatdawoud picture medhatdawoud  路  3Comments

Niggler picture Niggler  路  3Comments

will-stone picture will-stone  路  3Comments

davidnagli picture davidnagli  路  3Comments

philipodev picture philipodev  路  3Comments