jszip icon indicating copy to clipboard operation
jszip copied to clipboard

JSZip not working with Webpack

Open okbel opened this issue 9 years ago • 9 comments

I get this error while using Webpack

WARNING in ./bower_components/jszip/dist/jszip.js
Critical dependencies:
12:436-443 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./bower_components/jszip/dist/jszip.js 12:436-443

Also, requests the following modules: base64-js, ieee754, is-array

Does anybody have a solution? Thank you!

okbel avatar Jan 25 '16 14:01 okbel

How are you loading it? Importing it?

bf4 avatar Feb 01 '16 05:02 bf4

I get the same warning with a bower installation (but I get a fully functional JSZip object). When using bower to install JSZip, you won't get the dependencies and will need to use the dist/ file (hence the warning). If you use npm, a require("jszip") will work too, without warning.

dduponchel avatar Feb 02 '16 18:02 dduponchel

I loaded lib/index.js with the imports loader (bower install)

Imports?JSZIP!jszip

Where jszip is a resolve.alias to the index.js

B mobile phone

On Feb 2, 2016, at 12:26 PM, David Duponchel [email protected] wrote:

I get the same warning with a bower installation (but I get a fully functional JSZip object). When using bower to install JSZip, you won't get the dependencies and will need to use the dist/ file (hence the warning). If you use npm, a require("jszip") will work too, without warning.

— Reply to this email directly or view it on GitHub.

bf4 avatar Feb 03 '16 01:02 bf4

I loaded it through webpack.config.js, using alias

  resolve: {
      modulesDirectories: ['.', 'bower_components'],
      alias: {
        jszip: 'jszip/dist/jszip.js'
      }
   }

and I've got the error mentioned above

WARNING in ./bower_components/jszip/dist/jszip.js
Critical dependencies:
12:436-443 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./bower_components/jszip/dist/jszip.js 12:436-443

okbel avatar Feb 03 '16 15:02 okbel

@okbel I have

{
  resolve: {
    alias: {
              jszip: path.join(__dirname, 'bower_components/jszip/lib/index.js') // src
    }
  },
  loaders: [
   {  test: /bower_components\/jszip\/.*\.js$/, loader: 'imports?JSZIP=jszip' }
  ]
}

possibly try adding this=>window,define=>false... I'm using it a bit differently

bf4 avatar Feb 03 '16 16:02 bf4

any possible work arounds to make it work with webpack?

suryaiiit avatar Mar 16 '16 07:03 suryaiiit

@suryaiiit works for me with webpack as I've commented above. no workarounds, just using what webpack gives you

bf4 avatar Apr 19 '16 14:04 bf4

@jamesbillinger posted a solution to this over at https://github.com/SheetJS/js-xlsx/issues/397

In short, you just need to let webpack know that jszip is a pre-bundled module by adding

externals: [ {'./jszip': 'jszip'}]

in your webpack config.

Thanks @jamesbillinger! 👍

jabooth avatar May 04 '16 07:05 jabooth

Just thanks for all the sharing. What happened to me is, after I changed

taowangpro avatar Mar 23 '21 19:03 taowangpro