question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

module is not defined error in browser when using a bundled js file produced by AOT and rollup

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

While there has already been lot of talk and issues on module.id, This issues arises specifically after AOT and rollup. Following the AOT tutorial from angular.io website, after all the steps are successfully completed, and the whole application is in one build.js file, then running the application in browser throws error that “Uncaught ReferenceError: module is not defined”. I’m aware that obviously this is happening because plain JavaScript doesn’t know what “module” is.

Expected behavior

Should’t ngc or rollup take care of this during the build process so that browser doesn’t complain?

I’ve seen similar question on StackOverflow which is unanswered and a question in Google groups.

Can’t seem to find a solution

Please tell us about your environment:

  • Angular version: 2.0.1

  • Browser: [Chrome 53, haven’t tested elsewhere ]

  • Language: [all | TypeScript 2.0.3 | ES6/7 | ES5]

  • Node (for AoT issues): node --version = 4.6.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
singhjusrajcommented, Oct 3, 2016

@robwormald I’m aware that moduleis purely commonJS.

For JIT mode I’m using SystemJS.

While development I need to run application in JIT mode. But my question is how can I generate a rollup bundle with the same code?

Do I need to make changes in my components each time I need to generate a rollup build?

Thanks for you help

3reactions
Craig-Cookecommented, Feb 16, 2017

If your error is module is not defined after bundling using AOT just add the following to the head of your production index.html file:

<script>window.module = "name of your app";</script>

module is a global variable.

You don’t need this in JIT mode with systemjs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular AOT & Rollup - Uncaught ReferenceError: exports is ...
You can get the "exports is not defined" error if you are importing files with extensions other than .js . It looks like...
Read more >
ag-Grid Reference: Building with Angular with SystemJS
ag-Grid is a feature-rich data grid supporting major JavaScript Frameworks. This reference guide demonstrates building the Angular datagrid using SystemJS ...
Read more >
AOT and rollup - GoJS - Northwoods Software
and loading the go-debug.js file via the system.js module loader. I have no issues typescript compiling the app, the issue is with AOT...
Read more >
Getting started with Webpack Ahead-of-Time Configuration
The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser...
Read more >
Angular Performance Checklist - Taskade
For modern browsers with ES2015 modules and specific polyfills, ... blog.mgechev.com/2016/06/26/tree-shaking-angular2-production-build-rollup-javascript/.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found