Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollup wants me to create global variables. How can I use 'export default'?

I have a small app I am converting to use rollup. It uses ES6 modules - when I run rollup -c, it complains about one of my ES6 modules:

/js/monogram.js (imported by src\main.js)
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
/js/monogram.js (guessing 'drawMonogram')
created public\js\bundle.js in 311ms

The module monogram.js uses:

export default drawMonogram

I am importing it with:

import drawMonogram from '/js/monogram.js';

Both of these worked before rollup. Is this now not OK?

Should I actually make output.globals to specify a global name?

Why do I need a global variable? Is the global requirement from ES6 modules (I'd have thought modules would be in a functional scope) or rollup?

like image 258
mikemaccana Avatar asked Dec 17 '22 22:12

mikemaccana


1 Answers

Rollup's error is completely unrelated to the problem. It's simply not able to import the module at that path. Using ES6 modules in browser,

import drawMonogram from '/js/monogram.js';

Was relative to the web server root. However using rollup on the developmnt box,

import drawMonogram from '/js/monogram.js';

is considered relative to / on the hard disk. Using a relative import fixed the errror.

import drawMonogram from './monogram.js';
like image 92
mikemaccana Avatar answered Dec 25 '22 22:12

mikemaccana