-
Notifications
You must be signed in to change notification settings - Fork 126
Uncaught ReferenceError: global is not defined #6
Comments
Don't have time to implement this right now, but I reckon the best fix is to detect whether // intro for the whole bundle
var commonjsGlobal = typeof window !== 'undefined' ? window :
typeof global !== 'undefined' ? global :
this;
// individual module
var foo = (function (module, global) {
var exports = module.exports;
/* commonjs module happens */
return module.exports;
}({exports:{}}, commonjsGlobal);
export default foo; |
Added and released as 1.3.0 |
@Rich-Harris Thanks! |
Hi, An issue with Underscore.js that probably relates to this one: var previousUnderscore = root._;
^
TypeError: Cannot read property '_' of undefined Reproduce:
"rollup": "^0.22.0",
"rollup-plugin-commonjs": "^1.4.0",
"rollup-plugin-npm": "^1.1.0",
"underscore": ">=1.7.0"
import _ from 'underscore';
export default function foo() {
return _.map([1, 2, 3], function(num){ return num * 3; });
}
import commonjs from 'rollup-plugin-commonjs';
import npm from 'rollup-plugin-npm';
export default {
entry: 'lib.js',
dest: 'lib-bundle.js',
format: 'cjs',
plugins: [
npm({
main: true
}),
commonjs()
]
}
rollup -c rollup-config.js
node lib-bundle.js |
@hugomallet This might have been related to #31, and if so would be fixed now – please open a new issue if not |
This happens again with v3.0.1 in combination with
Works fine with v2.2.1. |
@herrstucki, hello. I see some attempts to capture proper global object in my bundle, but seems they are not enough. |
@StreetStrider this plugin generates this stuff typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {} Produce please minimal example |
@TrySound, yes I've detected this in my bundle. This expr assigned to name |
Got this code transformed into: if ( (global.Buffer && global.Buffer.isBuffer(obj)) ||
(global.ArrayBuffer && obj instanceof ArrayBuffer) ||
(global.Blob && obj instanceof Blob) ||
(commonjsGlobal.File && obj instanceof File)
) { in my bundle. Still digging. |
@TrySound, problem dissolves after clear install. Looks like something in caches or elsewhere obscures me. Everything works ok on |
Uncaught ReferenceError: global is not defined
at index.js:388
at empty (index.js:4)
at index.js:5 import 'fabric';
// create a wrapper around native canvas element (with id="c")
var canvas = new fabric.Canvas('c');
// create a rectangle object
var rect = new fabric.Rect({
left: 100,
top: 100,
fill: 'red',
width: 20,
height: 20
});
// "add" rectangle onto canvas
canvas.add(rect); |
I am getting this same message with the following versions:
and this config:
I have tried bundling two public libraries:
I get the same error with both. Any suggestions please? |
I get this trying to include import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder' No time to produce a minimal example right now, but I will as soon as possible - just wanted to confirm this as an ongoing issue. |
I had the same issue. I have found a workaround(hack). In rollup.config.js :
This defines the variable 'global' at the beginning of the bundle. I am somewhat new to the whole bundling process and if this is conceptually wrong, please let me know. However, my app works now 👍 |
Thanks @vitalis-wiens this fixed it for tonejs:
|
browserify defines
global
aswindow
aliasFor example this lib fails in browser
https://github.com/jbraithwaite/scroll-to-y
The text was updated successfully, but these errors were encountered: