Jszip: Rollup build errors

Created on 6 May 2020  Â·  2Comments  Â·  Source: Stuk/jszip

My goal is to use jszip in a browser application (UMD).

importing jszip (import JSZip from "jszip";) in an application bundled with Rollup causes the following build errors:

src/main.js → dist/jszip-rollup.umd.js...
(!) Missing shims for Node.js built-ins
Creating a browser bundle that depends on 'stream', 'events', 'buffer' and 'util'. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins
(!) Plugin node-resolve: preferring built-in module 'stream' over local alternative at 'stream', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Plugin node-resolve: preferring built-in module 'events' over local alternative at 'events', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Plugin node-resolve: preferring built-in module 'util' over local alternative at 'util', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Plugin node-resolve: preferring built-in module 'buffer' over local alternative at 'buffer', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
stream (imported by node_modules/readable-stream/readable.js, stream?commonjs-external, node_modules/readable-stream/lib/internal/streams/stream.js)
events (imported by node_modules/readable-stream/lib/_stream_readable.js, events?commonjs-external)
util (imported by node_modules/readable-stream/lib/_stream_readable.js, util?commonjs-external, node_modules/readable-stream/lib/internal/streams/BufferList.js, node_modules/inherits/inherits.js, node_modules/util-deprecate/node.js)
buffer (imported by node_modules/safe-buffer/index.js, buffer?commonjs-external)
(!) Circular dependencies
node_modules/readable-stream/lib/_stream_readable.js -> node_modules/readable-stream/lib/_stream_duplex.js -> node_modules/readable-stream/lib/_stream_readable.js
node_modules/readable-stream/lib/_stream_duplex.js -> node_modules/readable-stream/lib/_stream_writable.js -> node_modules/readable-stream/lib/_stream_duplex.js
node_modules/readable-stream/lib/_stream_duplex.js -> node_modules/readable-stream/lib/_stream_writable.js -> /var/www/html/rollup-jszip/node_modules/readable-stream/lib/_stream_duplex.js?commonjs-proxy -> node_modules/readable-stream/lib/_stream_duplex.js
...and 3 more
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
stream (guessing 'stream$1')
events (guessing 'events')
buffer (guessing 'buffer')
util (guessing 'util$6')

Sample project based on rollup-starter-lib

EDIT:
What I have gathered so far:

The error I currently have is when executing my build:

bundle.umd.js

...
      // implementation from standard node.js 'util' module
      ctor.super_ = superCtor;
      ctor.prototype = Object.create(superCtor.prototype, {
        constructor: {
          value: ctor,
          enumerable: false,
          writable: true,
          configurable: true
        }
...

TypeError: superCtor is undefined or Uncaught TypeError: Cannot read property 'prototype' of undefined

Most helpful comment

I'm not sure if this is the intended behavior but I had to use import JSZip from "jszip/dist/jszip"; instead.

All 2 comments

I'm not sure if this is the intended behavior but I had to use import JSZip from "jszip/dist/jszip"; instead.

thanks @hug0b for this report and the solution! In my case by just importing "jszip/dist/jszip" fixed it (no need to install any extra rollup plugin)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bertbeck picture bertbeck  Â·  5Comments

RUSHt picture RUSHt  Â·  5Comments

ryanakl picture ryanakl  Â·  4Comments

jimmywarting picture jimmywarting  Â·  4Comments

bbirdiman picture bbirdiman  Â·  5Comments