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

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

Closed
slowselfip opened this issue Nov 7, 2018 · 10 comments

Comments

@slowselfip
Copy link

slowselfip commented Nov 7, 2018

🐛 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
@johanberonius
Copy link

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.

@pocesar
Copy link
Contributor

pocesar commented Nov 19, 2018

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

@tjwlucas
Copy link

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...

@pocesar
Copy link
Contributor

pocesar commented Nov 24, 2018

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

@johanberonius
Copy link

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

@pocesar
Copy link
Contributor

pocesar commented Dec 4, 2018

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

@mallim
Copy link

mallim commented Feb 25, 2019

what will be the workaround for 1.11.0?

@pocesar
Copy link
Contributor

pocesar commented Feb 25, 2019

@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)

@zeroidentidad
Copy link

use parcel-bundler@1.9.7 stable version

@github-actions
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants
@pocesar @johanberonius @mallim @DeMoorJasper @zeroidentidad @slowselfip @tjwlucas and others