Closed
Description
Hi,
Just a documentation note.
Today is my first day opening rollup. I was getting You must supply options.moduleName for IIFE bundles
when I tried to bundle with format: 'iife'
It was pretty obvious what the issue was, after I found it in the wiki, but it took longer than it should've. Maybe I'm just tired.
I was following this:
https://github.com/rollup/rollup/wiki/Quickstart-Tutorial
and it doesn't mention setting moduleName: 'foo'
anywhere, even though it uses IIFE in the examples(?)
I dunno. Just wanted to give the feedback of a brand new person. Maybe I've gotten used to API docs being in README.md
Activity
proyb6 commentedon Dec 19, 2016
Yes, with compiled to IIFE, need to supply moduleName at least that I found on the search too
bahmutov/rollem@441c946
Victorystick commentedon Dec 20, 2016
So long as your entry doesn't export anything there isn't a need to supply a
moduleName
; the bundle is completely self-contained. But if you export things, Rollup needs to know what variable to export to. Which is why it'll ask for amoduleName
.Take a look at the different examples over on https://rollupjs.org/ with the output format set to Globals. You'll see what I mean. 😄
magwas commentedon Mar 2, 2017
I am here because I have encountered the same problem, and this issue is on the top of google.
However I cannot understand what you are talking about.
Where should I put moduleName: 'foo' ?
Upd: I was trying the following command line, and still got the error:
applecool commentedon Mar 14, 2017
@magwas Just add it inside the export default like this:
That should work 😃
ghost commentedon Mar 15, 2017
The HTTPs link here is insecure. Also,
Globals
is not an option for module format. @Victorystick I'm assuming you meant something else, but it's not clear from your wording. The OP is asking for fresh eyes and a review of the documentation for newcomers (as most of us are).shellscape commentedon Apr 19, 2017
I'm gonna go ahead and +1 this as the docs are painfully sparse. The error output doesn't point to anything and a google search for "You must supply options.moduleName for IIFE bundles" yielded only 4 results of which this issue was the top result.
cipri-tom commentedon Jul 2, 2017
same issue here (I've been using rollup for 2 days, tho' haha).
what @applecool means is to put that in your config file (
rollup.config.js
). It is needed in case you want to refer to your entry point as if it was a module.So if you do
then somewhere else in your code, like in a
<script>
tag (which doesn't support modules yet), you can sayvar app = new App();
(I'm not sure about thenew
).Please anyone correct me if I got something wrong.
ghost commentedon Jul 2, 2017
@cipri-tom you may find the following post from Rich Harris of value: https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c
shellscape commentedon Jul 2, 2017
How is this not in the documentation yet?
ghost commentedon Jul 2, 2017
@shellscape while programs are in development it's typical for docs to fall out of date. In those cases it's best to look for the information and, if not capable of finding it, find ways to help the project move forward constructively. The sheer fact this issue exists is documentation itself. It's living documentation. Because nothing in life is finite or static.
ghost commentedon Jul 2, 2017
https://github.com/rollup/rollup/wiki/Troubleshooting#ambiguous-default-export
Here's where you can help improve the documentation right now, @shellscape, should you desire.
Diti commentedon Nov 1, 2017
I came here to say what others have already said—as a newcomer, this error message is confusing, the documentation still doesn’t mention anything about setting a name and what it is useful for.
Thanks @cipri-tom for answering this issue in clear terms!
guybedford commentedon Feb 11, 2018
This definitely reads
options.name
in the message now.LeeeeeeM commentedon Nov 27, 2018
what if the module i will just read from file and get the iife Object from new Function, the moduleName option just bothers me
dheerajsuthar commentedon Jan 17, 2019
moduleName is just name now
michaelprescott commentedon Jan 30, 2019
What is it today? moduleName failed and now name fails with
Unknown input option: name.
lukastaegert commentedon Jan 30, 2019
It has been an output option for more than 1 1/2 years now and 25 Rollup versions which is about the same time when entry and dest became deprecated 😉
The current documentation on rollupjs.org is now always up to date: https://rollupjs.org/guide/en#output-name
dheerajsuthar commentedon Jan 30, 2019
2019 Кто еще здесь в этом году? 😉
cube-dan commentedon Feb 7, 2021
Adding my two cents here as this post is still on top of "teh googles" for the warning:
(!) If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.
... Sorry for the threadjack.I was trying to build Ladda on the command line, as an IIFE, and working in the UMD version of Spin.js, with a global variable name of Spin — as required in the Spin.js docs docs (see header "Installation" » "JS bundling").
To use the rollup transpiled version of Ladda you have to give the IIFE a var name to call from your js code. I chose to stick with what the Ladda docs specify;
Ladda
.From the Ladda js source directory, the whole command line invocation turned out to be:
Rollup kicked ass and I'm now sportin' a shiny new Ladda, on a old school (LAMP) website. Thanks for the sweet bundler team Rollup!
NOTES:
Ladda:
--name Ladda
resolves the warning:(!) If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.
--globals spin.js:Spin
resolves the warning:(!) Unresolved dependencies
... and sets the dependencies imported variable name to what Spin exports in it’s UMD version. ... Which I didn't end up using because of the Spin.js authors super scary warning: "Note that the UMD version is only available as a temporary workaround."
Spin:
To get this all working with the sources provided by composer via asset-packagist.org, I also had to transpile spin.js as a UMD. For the sake of future googleers, you'll need to do this also:
--silent
keeps rollup from barfing out this important, but unnecessary for my use case, message: