After using {corejs: 3} option for both @babel/preset-env and @babel/plugin-transform-runtime, and using @babel/runtime-corejs3, my tests are failing with the following error:
/node_modules/core-js-pure/internals/well-known-symbol.js:10
return store[name] || (store[name] = NATIVE_SYMBOL && Symbol[name]
^
TypeError: Cannot read property 'iterator' of undefined
After using
{corejs: 3}option for both@babel/preset-envand@babel/plugin-transform-runtime...
You should you corejs: 3 in @babel/preset-env OR in @babel/plugin-transform-runtime, but not together.
I am using the useBuiltins: 'usage' option for @babel/preset-env, so I get this warning if I remove corejs: 3 from options:
WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version.
Currently, we assume version 2.x when no version is passed.
Since this default version will likely change in future versions of Babel,
we recommend explicitly setting the core-js version you are using via the `corejs` option.
Ok, let say in other words: you should use useBuiltIns option of preset-env OR corejs option of runtime, but not together.
https://github.com/babel/babel/issues/10121#issuecomment-505002153
yeah I just found that out :)
But even after this, I get the exact same error.
I hope that you don't transform core-js in your node_modules?
No, I don't think so.
Scrolling down, I see another error:
/node_modules/@babel/core/lib/config/files/configuration.js:206
throw err;
^
TypeError: /.babelrc.js: Error while loading config - Cannot read property 'species' of undefined
at module.exports (/node_modules/core-js-pure/internals/well-known-symbol.js:10:63)
Seems it's a similar error.
Take a look at well-known-symbol.js code. NATIVE_SYMBOL && Symbol[name] will be executed only when NATIVE_SYMBOL is true. NATIVE_SYMBOL will be true only when Symbol is a function. So this error is possible only if this code is changed (most likely by transpiler) or someone directly removed global Symbol before some parts of core-js will be executed.
I will check what is causing this, but I have a question. The environment where these tests are being run is Node 10.14.1, where Symbol is natively supported. Why is Symbol not available here? Why am I encountering the polyfill of Symbol?
It should not be polyfilled, just wrapped in you uses a version without global pollution.
Yeah, so when it calls Symbol[name], the Symbol should be the one in the node environment, right? In which case can this turn up undefined?
See this comment, this is exactly the answer to your question.
Hi, just putting it there if it helps:

While debugging, I found that Symbol from closure is undefined at this time, but global.Symbol is not. Does that tell you anything?
When I replace Symbol with global.Symbol, and then apply breakpoint, I find that global.Symbol is undefined, while Symbol from closure is not. 馃し鈥嶁檪

In another case where I try to use Symbol || global.Symbol, both are undefined
Looks like core-js code is transpiled. Could you check it in your configs, in the bundle?
That's the thing, my build is working fine.
But when I run mocha test, which I do by loading @babel/register before running tests, I get this error. As such I don't have any bundle to check.
It seems that the error was due to me doing window.Math = Math in the mocha entry file to work around this issue in jsdom with RxJS:
https://github.com/ReactiveX/rxjs/issues/2651#issuecomment-338648013
Removing this line fixed the issue, however I wonder how could it wipe out global Symbol? 馃
Interesting. So, seems you use mocked window and, because of window.Math === Math, it passes current global object detection. But it's not a real global object, so you try to use core-js in a broken environment. You should use core-js before that. Seems the issue resolved.
Yes it is, thanks!
https://github.com/babel/babel/issues/10133
I have a query regarding corejs and babel. Could you please help me there as well.
Thanks! 馃槃
@nicolo-ribaudo already answered to this question.
Most helpful comment
You should you
corejs: 3in@babel/preset-envOR in@babel/plugin-transform-runtime, but not together.