<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
I am upgrading to babel v7.0.0. I am using mocha for my unit tests, v6.1.4.</p>
<p dir="auto">In <code class="notranslate">mocha.opts</code> I have specified <code class="notranslate">@babel/register</code> as the compiler and <code class="notranslate">@babel/polyfill</code> for the necessary polyfills.</p>
<p dir="auto">My tests run fine except when spreading objects. Everywhere that an object is being spread in the tests I encounter this error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: Invalid attempt to spread non-iterable instance"><pre class="notranslate"><code class="notranslate">TypeError: Invalid attempt to spread non-iterable instance
</code></pre></div>
<p dir="auto">This is also impacting my test reporter, mocha-multi. The stack trace for that error takes me to an object-spread.</p>
<p dir="auto">I have tried adding the <code class="notranslate">@babel/plugin-proposal-object-rest-spread</code> as a plugin in <code class="notranslate">.babelrc</code> for my test env with no success.</p>
<p dir="auto"><strong>Expected behavior/code</strong><br>
I expect to be able to execute my unit tests, and have babel compile all the latest js features, like object-spread.</p>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
	&quot;presets&quot;: [&quot;@babel/preset-react&quot;, &quot;@babel/preset-env&quot;, &quot;react-app&quot;],
	&quot;env&quot;: {
		&quot;development&quot;: {
			&quot;plugins&quot;: [&quot;react-hot-loader/babel&quot;]
		},
		&quot;test&quot;: {
			&quot;plugins&quot;: [
				[&quot;babel-plugin-webpack-alias-7&quot;, { &quot;config&quot;: &quot;./build_config/webpack.common.js&quot; }],
				&quot;istanbul&quot;,
				&quot;dynamic-import-node&quot;,
				&quot;@babel/plugin-proposal-object-rest-spread&quot;
			]
		},
		&quot;production&quot;: {
			&quot;plugins&quot;: [&quot;transform-react-remove-prop-types&quot;, [&quot;recharts&quot;]]
		}
	}
}"><pre class="notranslate"><span class="pl-kos">{</span>
	<span class="pl-s">"presets"</span>: <span class="pl-kos">[</span><span class="pl-s">"@babel/preset-react"</span><span class="pl-kos">,</span> <span class="pl-s">"@babel/preset-env"</span><span class="pl-kos">,</span> <span class="pl-s">"react-app"</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
	<span class="pl-s">"env"</span>: <span class="pl-kos">{</span>
		<span class="pl-s">"development"</span>: <span class="pl-kos">{</span>
			<span class="pl-s">"plugins"</span>: <span class="pl-kos">[</span><span class="pl-s">"react-hot-loader/babel"</span><span class="pl-kos">]</span>
		<span class="pl-kos">}</span><span class="pl-kos">,</span>
		<span class="pl-s">"test"</span>: <span class="pl-kos">{</span>
			<span class="pl-s">"plugins"</span>: <span class="pl-kos">[</span>
				<span class="pl-kos">[</span><span class="pl-s">"babel-plugin-webpack-alias-7"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-s">"config"</span>: <span class="pl-s">"./build_config/webpack.common.js"</span> <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
				<span class="pl-s">"istanbul"</span><span class="pl-kos">,</span>
				<span class="pl-s">"dynamic-import-node"</span><span class="pl-kos">,</span>
				<span class="pl-s">"@babel/plugin-proposal-object-rest-spread"</span>
			<span class="pl-kos">]</span>
		<span class="pl-kos">}</span><span class="pl-kos">,</span>
		<span class="pl-s">"production"</span>: <span class="pl-kos">{</span>
			<span class="pl-s">"plugins"</span>: <span class="pl-kos">[</span><span class="pl-s">"transform-react-remove-prop-types"</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s">"recharts"</span><span class="pl-kos">]</span><span class="pl-kos">]</span>
		<span class="pl-kos">}</span>
	<span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">mocha.opts</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--require @babel/register
--require ./test/compilers/index.js
--require @babel/polyfill
--require test/enzymeSetup.js
--recursive
--reporter mocha-multi
--reporter-options spec=-,mocha-sonar-generic-test-coverage=coverage/sonar-unit.xml,mocha-jenkins-reporter=-,mocha-duplicate-reporter=-
--colors
--inline-diffs
test/**/*Test.{js,jsx}"><pre class="notranslate"><code class="notranslate">--require @babel/register
--require ./test/compilers/index.js
--require @babel/polyfill
--require test/enzymeSetup.js
--recursive
--reporter mocha-multi
--reporter-options spec=-,mocha-sonar-generic-test-coverage=coverage/sonar-unit.xml,mocha-jenkins-reporter=-,mocha-duplicate-reporter=-
--colors
--inline-diffs
test/**/*Test.{js,jsx}
</code></pre></div>
<p dir="auto">scripts</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    &quot;test&quot;: &quot;cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary --reporter=text mocha&quot;,
    &quot;test:nc&quot;: &quot;cross-env NODE_ENV=test --reporter=text-summary --reporter=text --reporter=html mocha&quot;,"><pre class="notranslate"><code class="notranslate">    "test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary --reporter=text mocha",
    "test:nc": "cross-env NODE_ENV=test --reporter=text-summary --reporter=text --reporter=html mocha",
</code></pre></div>
<p dir="auto">package.json</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    &quot;@babel/core&quot;: &quot;7.4.4&quot;,
    &quot;@babel/polyfill&quot;: &quot;^7.4.4&quot;,
    &quot;@babel/preset-env&quot;: &quot;^7.4.4&quot;,
    &quot;@babel/preset-react&quot;: &quot;^7.0.0&quot;,
    &quot;@babel/register&quot;: &quot;^7.4.4&quot;,
    &quot;autoprefixer&quot;: &quot;^7.1.2&quot;,
    &quot;babel-eslint&quot;: &quot;^9.0.0&quot;,
    &quot;babel-loader&quot;: &quot;^8.0.5&quot;,
    &quot;babel-plugin-dynamic-import-node&quot;: &quot;^2.2.0&quot;,
    &quot;babel-plugin-istanbul&quot;: &quot;^5.0.1&quot;,
    &quot;babel-plugin-recharts&quot;: &quot;^1.1.0&quot;,
    &quot;babel-plugin-transform-react-remove-prop-types&quot;: &quot;^0.4.6&quot;,
    &quot;babel-plugin-webpack-alias-7&quot;: &quot;^0.1.1&quot;,
    &quot;babel-preset-react-app&quot;: &quot;^8.0.0&quot;,
    &quot;chai&quot;: &quot;^4.2.0&quot;,
    &quot;chai-as-promised&quot;: &quot;^7.1.1&quot;,
    &quot;copy-webpack-plugin&quot;: &quot;^5.0.3&quot;,
    &quot;copyfiles&quot;: &quot;^2.1.0&quot;,
    &quot;cross-env&quot;: &quot;^5.0.1&quot;,
    &quot;css-loader&quot;: &quot;^2.1.1&quot;,
    &quot;dotenv&quot;: &quot;^8.0.0&quot;,
    &quot;enzyme&quot;: &quot;^3.8.0&quot;,
    &quot;enzyme-adapter-react-16&quot;: &quot;^1.6.0&quot;,
    &quot;eslint&quot;: &quot;^5.15.3&quot;,
    &quot;eslint-config-airbnb&quot;: &quot;^17.1.0&quot;,
    &quot;eslint-config-prettier&quot;: &quot;^3.1.0&quot;,
    &quot;eslint-import-resolver-webpack&quot;: &quot;^0.10.1&quot;,
    &quot;eslint-loader&quot;: &quot;^2.1.1&quot;,
    &quot;eslint-plugin-import&quot;: &quot;^2.14.0&quot;,
    &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.1.1&quot;,
    &quot;eslint-plugin-prettier&quot;: &quot;^2.6.2&quot;,
    &quot;eslint-plugin-react&quot;: &quot;^7.11.0&quot;,
    &quot;eslint-plugin-react-hooks&quot;: &quot;^1.0.1&quot;,
    &quot;eslint-plugin-testcafe&quot;: &quot;^0.2.1&quot;,
    &quot;extract-text-webpack-plugin&quot;: &quot;^4.0.0-alpha.0&quot;,
    &quot;file-loader&quot;: &quot;^3.0.1&quot;,
    &quot;html-webpack-plugin&quot;: &quot;^3.2.0&quot;,
    &quot;jsdom&quot;: &quot;9.0.0&quot;,
    &quot;mocha&quot;: &quot;^6.1.4&quot;,
    &quot;mocha-duplicate-reporter&quot;: &quot;^0.2.1&quot;,
    &quot;mocha-jenkins-reporter&quot;: &quot;^0.4.1&quot;,
    &quot;mocha-multi&quot;: &quot;^1.1.0&quot;,
    &quot;mocha-sonar-generic-test-coverage&quot;: &quot;^0.0.6&quot;,
    &quot;node-sass&quot;: &quot;^4.9.3&quot;,
    &quot;null-loader&quot;: &quot;^1.0.0&quot;,
    &quot;nyc&quot;: &quot;^13.0.1&quot;,
    &quot;postcss-loader&quot;: &quot;^2.0.6&quot;,
    &quot;preload-webpack-plugin&quot;: &quot;^2.3.0&quot;,
    &quot;process-finder&quot;: &quot;1.0.0&quot;,
    &quot;react-hot-loader&quot;: &quot;^4.8.4&quot;,
    &quot;redux-mock-store&quot;: &quot;^1.2.2&quot;,
    &quot;retire&quot;: &quot;^2.0.2&quot;,
    &quot;rimraf&quot;: &quot;^2.5.4&quot;,
    &quot;sass-loader&quot;: &quot;^6.0.6&quot;,
    &quot;script-ext-html-webpack-plugin&quot;: &quot;^2.1.3&quot;,
    &quot;semver&quot;: &quot;^5.3.0&quot;,
    &quot;simple-mock&quot;: &quot;^0.7.3&quot;,
    &quot;sinon&quot;: &quot;^7.2.2&quot;,
    &quot;style-loader&quot;: &quot;^0.20.2&quot;,
    &quot;stylelint&quot;: &quot;^9.10.1&quot;,
    &quot;stylelint-config-standard&quot;: &quot;^18.0.0&quot;,
    &quot;testcafe&quot;: &quot;^1.0.0&quot;,
    &quot;tree-kill&quot;: &quot;1.2.0&quot;,
    &quot;url-join&quot;: &quot;^4.0.0&quot;,
    &quot;url-loader&quot;: &quot;^1.1.2&quot;,
    &quot;webpack&quot;: &quot;^4.30.0&quot;,
    &quot;webpack-bundle-analyzer&quot;: &quot;^3.3.2&quot;,
    &quot;webpack-cli&quot;: &quot;^3.3.1&quot;,
    &quot;webpack-dev-middleware&quot;: &quot;^3.6.2&quot;,
    &quot;webpack-dev-server&quot;: &quot;^3.3.1&quot;,
    &quot;webpack-merge&quot;: &quot;^4.2.1&quot;"><pre class="notranslate"><code class="notranslate">    "@babel/core": "7.4.4",
    "@babel/polyfill": "^7.4.4",
    "@babel/preset-env": "^7.4.4",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.4.4",
    "autoprefixer": "^7.1.2",
    "babel-eslint": "^9.0.0",
    "babel-loader": "^8.0.5",
    "babel-plugin-dynamic-import-node": "^2.2.0",
    "babel-plugin-istanbul": "^5.0.1",
    "babel-plugin-recharts": "^1.1.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.6",
    "babel-plugin-webpack-alias-7": "^0.1.1",
    "babel-preset-react-app": "^8.0.0",
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "copy-webpack-plugin": "^5.0.3",
    "copyfiles": "^2.1.0",
    "cross-env": "^5.0.1",
    "css-loader": "^2.1.1",
    "dotenv": "^8.0.0",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.6.0",
    "eslint": "^5.15.3",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-config-prettier": "^3.1.0",
    "eslint-import-resolver-webpack": "^0.10.1",
    "eslint-loader": "^2.1.1",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.1.1",
    "eslint-plugin-prettier": "^2.6.2",
    "eslint-plugin-react": "^7.11.0",
    "eslint-plugin-react-hooks": "^1.0.1",
    "eslint-plugin-testcafe": "^0.2.1",
    "extract-text-webpack-plugin": "^4.0.0-alpha.0",
    "file-loader": "^3.0.1",
    "html-webpack-plugin": "^3.2.0",
    "jsdom": "9.0.0",
    "mocha": "^6.1.4",
    "mocha-duplicate-reporter": "^0.2.1",
    "mocha-jenkins-reporter": "^0.4.1",
    "mocha-multi": "^1.1.0",
    "mocha-sonar-generic-test-coverage": "^0.0.6",
    "node-sass": "^4.9.3",
    "null-loader": "^1.0.0",
    "nyc": "^13.0.1",
    "postcss-loader": "^2.0.6",
    "preload-webpack-plugin": "^2.3.0",
    "process-finder": "1.0.0",
    "react-hot-loader": "^4.8.4",
    "redux-mock-store": "^1.2.2",
    "retire": "^2.0.2",
    "rimraf": "^2.5.4",
    "sass-loader": "^6.0.6",
    "script-ext-html-webpack-plugin": "^2.1.3",
    "semver": "^5.3.0",
    "simple-mock": "^0.7.3",
    "sinon": "^7.2.2",
    "style-loader": "^0.20.2",
    "stylelint": "^9.10.1",
    "stylelint-config-standard": "^18.0.0",
    "testcafe": "^1.0.0",
    "tree-kill": "1.2.0",
    "url-join": "^4.0.0",
    "url-loader": "^1.1.2",
    "webpack": "^4.30.0",
    "webpack-bundle-analyzer": "^3.3.2",
    "webpack-cli": "^3.3.1",
    "webpack-dev-middleware": "^3.6.2",
    "webpack-dev-server": "^3.3.1",
    "webpack-merge": "^4.2.1"
</code></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): v7.0.0</li>
<li>Node/npm version: Node v10.15.0 - npm v6.7.0</li>
<li>OS: OSX 10.14.3</li>
<li>Monorepo: no</li>
<li>How you are using Babel: @babel/register</li>
</ul>
<p dir="auto"><strong>Additional context/Screenshots</strong><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24981281/57184532-85ffbb80-6e71-11e9-8ed3-bed7e7b585c3.png"><img width="1082" alt="Screen Shot 2019-05-04 at 1 34 38 PM" src="https://user-images.githubusercontent.com/24981281/57184532-85ffbb80-6e71-11e9-8ed3-bed7e7b585c3.png" style="max-width: 100%;"></a></p>
<h3 dir="auto">Is this a bug report or feature request?</h3>
<p dir="auto">More a discussion which may leads to a feature request in <code class="notranslate">@babel/preset-env</code>.</p>
<h3 dir="auto">Summary</h3>
<p dir="auto">The <code class="notranslate">useBuiltIns</code> features is great but its usage may not be appropriate for libraries because they affect the global scope.</p>
<p dir="auto"><code class="notranslate">@babel/plugin-transform-runtime</code> approach is nice but it does not currently supports targets like <code class="notranslate">@babel/preset-env</code>.</p>
<h3 dir="auto">Input Code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var a = new Promise();"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Promise</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Babel/Babylon Configuration (.babelrc, package.json, cli command)</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  presets: [
    [&quot;env&quot;, {
      targets: {
        node: '6'
      }
    }]
  ]
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"env"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
      <span class="pl-c1">targets</span>: <span class="pl-kos">{</span>
        <span class="pl-c1">node</span>: <span class="pl-s">'6'</span>
      <span class="pl-kos">}</span>
    <span class="pl-kos">}</span><span class="pl-kos">]</span>
  <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Current Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import &quot;core-js/modules/es6.promise&quot;;
var a = new Promise();"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s">"core-js/modules/es6.promise"</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Promise</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import _promise from &quot;core-js/es6.promise&quot;;
var a = new _promise();"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">_promise</span> <span class="pl-k">from</span> <span class="pl-s">"core-js/es6.promise"</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-s1">_promise</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">Maybe a new setting in <code class="notranslate">@babel/preset-env</code> which would act similarly to <code class="notranslate">useBuiltIns</code> but without polluting the global scope, like <code class="notranslate">@babel/plugin-transform-runtime</code> does.</p>
<h3 dir="auto">Context</h3>


<h3 dir="auto">Your Environment</h3>

<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>7.0.0-beta.38</td>
</tr>
<tr>
<td>Babylon</td>
<td></td>
</tr>
<tr>
<td>node</td>
<td></td>
</tr>
<tr>
<td>npm</td>
<td></td>
</tr>
<tr>
<td>Operating System</td>
<td></td>
</tr>
</tbody>
</table>