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

gulp-babel : Cannot set property 'svg4everybody' of undefined for root #162

Open
LouVerdun opened this issue Jun 1, 2017 · 10 comments
Open

Comments

@LouVerdun
Copy link

Hello everyone,

After adding gulp-babel to my JS tasks, svg4everybody started to display this error in the console :

Uncaught TypeError: Cannot set property 'svg4everybody' of undefined

It looks like root refers to undefined when in strict mode (automatically added by gulp-babel). This line is causing the problems (line 10 but other parts of the script are affected) :

"object" == typeof module && module.exports ? module.exports = factory() : root.svg4everybody = factory();

My workaround to make it work was to exclude the file from gulp tasks and include it manually in the document. Is there any fix for this issue ? Does anyone found a workaround for it (not overkill) ?

@stephanepericat
Copy link

i have this issue as well using babel and webpack, because the lib tries to assign this for the context and it turns out to be undefined in the context of the webpack build file.

@stephanepericat
Copy link

stephanepericat commented Aug 8, 2017

this could be fixed by assigning window instead of this for the context

@ghost
Copy link

ghost commented Aug 11, 2017

@stephanepericat See #111

@DanielRuf
Copy link

Same here for a normal gulp build.

@DanielRuf
Copy link

Solution: define root for browsers

!function(root, factory) {
    if(root === undefined) root = window;
    "function" == typeof define && define.amd ? // AMD. Register as an anonymous module unless amdModuleId is set

@oprokidnev
Copy link

This one configuration of babel worked for me.

{
  "presets": [ [ "es2015", { modules: false } ] ]
}

@DanielRuf
Copy link

@oprokidnev

This would change it for your whole bundle.

@DanielRuf
Copy link

See #171

@Dan9boi
Copy link

Dan9boi commented Nov 27, 2017

I have this same issue. Is there any news for a new release @jonathantneal ?

@JeremyEnglert
Copy link

Still running into this issue. Anyone find a workaround?

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

No branches or pull requests

6 participants