gilbarbara / react-floater

Advanced tooltips for React
https://codesandbox.io/s/github/gilbarbara/react-floater/tree/main/demo
MIT License
220 stars 37 forks source link

`global` is undefined #75

Closed ashubham closed 4 years ago

ashubham commented 4 years ago

🐛 Bug Report

When I am trying to use the es build of the library with Rollup, I see this error:

Unexpected Syntax: global is not defined

This is related to the issue I am seeing: https://github.com/gilbarbara/react-floater/pull/59

To Reproduce

Use the library with rollup, with target es.

Expected behavior

global is not in the ES6 spec and should not be implicitly assumed to have a value. Maybe have something like var global = typeof self !== undefined ? self : this; on top of the module.

gilbarbara commented 4 years ago

hey @ashubham Check the UMD config for the setup required.

ashubham commented 4 years ago

@gilbarbara I am not using the UMD bundle, I am using rollup to bundle the application as an es target. Use of global keyword inside ES modules is non standard, which is throwing errors.

dustinknopoff commented 3 years ago

Hi! I see that you've already closed this @gilbarbara but I'm running into the same issue.

My rollup config is set to es format but receiving errors around using global. Do you have any suggestions to resolve this?

If it narrows the problem space any, I'm not experiencing this problem when building on macOS but I am experiencing it on Ubuntu 18.0.4 LTS

ashubham commented 3 years ago

@dustinknopoff I used this workaround, basically create a rollup plugin like this:

export function patchReactFloater() {
    return {
        name: 'patch-react-floater',
        transform(code, id) {
            if(id.endsWith('react-floater/es/index.js')) {
                return `var global = typeof self !== undefined ? self : this;\n${code}`
            }
        }
    }
}

Then use it in the plugins of your rollup config.