Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Only one instance of babel-polyfill is allowed #121

Closed
AlanFoster opened this issue Apr 12, 2016 · 10 comments
Closed

Only one instance of babel-polyfill is allowed #121

AlanFoster opened this issue Apr 12, 2016 · 10 comments

Comments

@AlanFoster
Copy link

Naively attempting to switch out babel-loader with awesome-typescript-loader within webpack throws the following babel-polyfill error

> gulp watch
[23:47:05] Using gulpfile ~/app/gulpfile.js
[23:47:05] Starting 'watch'...
[23:47:05] Plumber found unhandled error:
 Error in plugin 'webpack-stream'
Message:
    only one instance of babel-polyfill is allowed
[23:47:05] Version: webpack 1.12.14

ERROR in only one instance of babel-polyfill is allowed
[23:47:05] webpack is watching for changes

With the following webpack snippet

    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'awesome-typescript'
      }
    ]
@dsebastien
Copy link

We have the same issue and it's quite difficult to troubleshoot. @AlanFoster have you found anything?

@drywolf
Copy link

drywolf commented Apr 20, 2016

I had the same issue and am still having it when I try to enable awesome-typescript-loader in my webpack config.
To get back to work I switched back to ts-loader which does not show that problem at all, but still has its own quirks.

PS: I'm building .ts/.tsx projects though, not .jsx

In my case I have a node_module called ui-lib that is linked via linklocal (symbolic links) into the node_modules of my app project. Both modules have awesome-typescript-loader in their package.json. That should be the trigger scenario for the above error message in my case, since there are two instances of the babel-polyfill module resolved in the app module dependency tree.

@s-panferov
Copy link
Owner

s-panferov commented Apr 21, 2016

As I can see, this issue appears when two different libraries require two different versions of babel-polyfill. It's hard to do something with this, unfortunately :(

I can offer you one hacky and ugly solution, but I believe it will work:

loader: 'awesome-typescript-loader/dist.babel/index'

This will work beginning with 0.17.0-rc.7

I'll think about how to make it better.

@drywolf
Copy link

drywolf commented Apr 21, 2016

Hi @s-panferov

Thanks for looking into it.

I just tried out the new version 0.17.0-rc.7 and the mentioned loader string 'awesome-typescript-loader/dist.babel/index', but I get the following error when running webpack:

Module build failed: ReferenceError: regeneratorRuntime is not defined
    at Object.loader (c:\_some_path_\node_modules\awesome-typescript-loader\dist.babel\index.js:56:44)

@drywolf
Copy link

drywolf commented Apr 21, 2016

I just patched my dist.babel/index.js files (in both my modules) manually with the following code:

'use strict';

if (!global._babelPolyfill)
    require('babel-polyfill');

...
...
...

This works around the issue for me, not sure if it's a good idea but so far it seems to work just fine.

@s-panferov
Copy link
Owner

@drywolf your solution is good, but another library may be included afterwards and throw, because require('babel-polyfill'); had been included already.

@s-panferov s-panferov added the bug label Apr 24, 2016
@messo
Copy link

messo commented May 9, 2016

Hey!

I am making a multi-module structure, and both module needs to have awesome-typescript-loader (the parent has the webpack.config.js, and the child itself is composed of typescript files)

I am experiencing the same issue, what do you recommend?

@s-panferov
Copy link
Owner

Require guard added in v0.18.0, please try.

@messo
Copy link

messo commented May 13, 2016

works for me! Thanks!

@AlanFoster
Copy link
Author

Thanks for the fix 👍

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

No branches or pull requests

5 participants