简体   繁体   中英

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?

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM