Skip to content

'You must supply options.moduleName for IIFE bundles' #1157

Closed
@laduke

Description

@laduke

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

proyb6 commented on Dec 19, 2016

@proyb6

Yes, with compiled to IIFE, need to supply moduleName at least that I found on the search too
bahmutov/rollem@441c946

Victorystick

Victorystick commented on Dec 20, 2016

@Victorystick
Contributor

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 a moduleName.

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

magwas commented on Mar 2, 2017

@magwas

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:

# rollup --format=iife --output=jsunit/ajax-test.js --moduleName ajaxtest site/js/unittests/ajax-test.js
🚨   You must supply options.moduleName for IIFE bundles
applecool

applecool commented on Mar 14, 2017

@applecool

@magwas Just add it inside the export default like this:

export default {
  entry: 'src/app.js',
  format: 'iife',
  moduleName: 'foo',
  dest: 'src/build.js',
...
}

That should work 😃

ghost

ghost commented on Mar 15, 2017

@ghost

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.

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

shellscape commented on Apr 19, 2017

@shellscape
Contributor

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

cipri-tom commented on Jul 2, 2017

@cipri-tom

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

export default {
  entry: 'src/App.js',
  format: 'iife',
  moduleName: 'App',
  dest: 'src/build.js',
...
}

then somewhere else in your code, like in a <script> tag (which doesn't support modules yet), you can say var app = new App(); (I'm not sure about the new).

Please anyone correct me if I got something wrong.

ghost

ghost commented on Jul 2, 2017

@ghost
shellscape

shellscape commented on Jul 2, 2017

@shellscape
Contributor

How is this not in the documentation yet?

ghost

ghost commented on Jul 2, 2017

@ghost

@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

ghost commented on Jul 2, 2017

@ghost

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

Diti commented on Nov 1, 2017

@Diti

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

guybedford commented on Feb 11, 2018

@guybedford
Contributor

This definitely reads options.name in the message now.

LeeeeeeM

LeeeeeeM commented on Nov 27, 2018

@LeeeeeeM

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

dheerajsuthar commented on Jan 17, 2019

@dheerajsuthar

@magwas Just add it inside the export default like this:

export default {
  entry: 'src/app.js',
  format: 'iife',
  moduleName: 'foo',
  dest: 'src/build.js',
...
}

That should work 😃

moduleName is just name now

michaelprescott

michaelprescott commented on Jan 30, 2019

@michaelprescott

@magwas Just add it inside the export default like this:

export default {
  entry: 'src/app.js',
  format: 'iife',
  moduleName: 'foo',
  dest: 'src/build.js',
...
}

That should work 😃

moduleName is just name now

What is it today? moduleName failed and now name fails with Unknown input option: name.

lukastaegert

lukastaegert commented on Jan 30, 2019

@lukastaegert
Member

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

dheerajsuthar commented on Jan 30, 2019

@dheerajsuthar

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

2019 Кто еще здесь в этом году? 😉

cube-dan

cube-dan commented on Feb 7, 2021

@cube-dan

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 --name Ladda --globals spin.js:Spin --input ladda.js --format iife --file ladda.iife.js

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:

rollup --silent --name Spin --input spin.js --format umd --file spin.umd.js

--silent keeps rollup from barfing out this important, but unnecessary for my use case, message:

(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
spin.js
1: var __assign = (this && this.__assign) || function () {
                    ^
2:     __assign = Object.assign || function(t) {
3:         for (var s, i = 1, n = arguments.length; i < n; i++) {
...and 1 other occurrence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @laduke@shellscape@michaelprescott@Diti@guybedford

        Issue actions

          'You must supply options.moduleName for IIFE bundles' · Issue #1157 · rollup/rollup