Skip to content

Cannot use requirejs to load in a web app that runs in browser #464

@mitchwilson

Description

@mitchwilson

When I use requirejs in a Web page to load jszip.js, like so:

require(['public/javascripts/jszip'], function(file){
    window.JSZip = file;
});

I get this error: "Error: Module name "stream" has not been loaded yet for context: _. Use require([])"

The line of code causing the error in jszip.js is: module.exports = require("stream");

The stream module is a nodejs module. I don't have the stream module in my web app, hence the error.

It appears that using requirejs to load jszip leads jszip to assume it's being loaded in a nodejs app. So it initializes itself as if in a nodejs environment. But I am loading it in a web page using requirejs.

Also, the error occurs when using the new operator to load jszip, like so (if requirejs is also loaded in page):

var zip = new JSZip();

Is it possible to load jszip using requirejs in a web app that runs in the browser and not in nodejs? My app is an existing app that uses requirejs, so I have no choice. As is, without modifying jszip, there is not a way to use jszip in a web app, without a requirejs error, in an app that uses requirejs in the browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions