最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin6浏览0评论

I have a small app I am converting to use rollup. It uses ES6 modules - when I run rollup -c, it plains 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?

I have a small app I am converting to use rollup. It uses ES6 modules - when I run rollup -c, it plains 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?

Share Improve this question edited Apr 21, 2021 at 8:49 mikemaccana asked Jul 17, 2018 at 21:37 mikemaccanamikemaccana 123k110 gold badges428 silver badges531 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

Rollup's error is pletely 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';
发布评论

评论列表(0)

  1. 暂无评论