Jimp: Can't load with webpack

Created on 13 Jul 2016  路  11Comments  路  Source: oliver-moran/jimp

When I try executing the browser file jimp.js with webpack using no loader and/or using the script loader I get (these execute the files's content in the global context)

Uncaught ReferenceError: encode is not defined

To make it harder when I use the raw so that I create a script and paste the content inside the script, as so I get:

Uncaught TypeError: Cannot assign to read only property 'window' of object '#'

Also if I assign an id to the parent script it'll be exposed in the main window.

It seems to me that somehow you are checking on the existance of the script tag and that it should have a src.

This makes the library useless for bundling and forces to be loaded by pasting directly into the HTML.

Most helpful comment

@AbhishekBharadwajTME , I ended up using lwip. But the first workaround for jimp is to import v0.2.27 and update it's dependency bmp-js, to 0.0.2.

Another way is to import jimp from master:
{ "dependencies": { "jimp": "github:oliver-moran/jimp#master" } }

Good luck

All 11 comments

Is this the same issue as here: https://github.com/oliver-moran/jimp/issues/75#issuecomment-214939959

I think this is fixed in the latest version. Can you retest? Thanks.

Uncaught ReferenceError: encode is not defined

nope :/

i++;}if(this.extraBytes>0){var fillOffset=this.pos+y*rowBytes+this.width*3;tempBuffer.fill(0,fillOffset,fillOffset+this.extraBytes);}}return tempBuffer;};module.exports=encode=function encode(imgData,quality){if(typeof quality==='undefined')quality=100;var encoder=new BmpEncoder(imgData);var data=encoder.encode();return{data:data,width:imgData.width,height:imgData.height};};}).call(this,require("buffer").Buffer);},{"buffer":14}],8:[function(require,module,exports){},{}],9:[function(require,module,exports){(function(process,Buffer){var msg=require('pako/lib/zlib/messages');var zstream=require('pako/lib/zlib/zstream');var zlib_deflate=require('pako/lib/zlib/deflate.js');var zlib_inflate=require('pako/lib/zlib/inflate.js');var constants=require('pako/lib/zlib/constants');for(var key in constants){exports[key]=constants[key];}// zlib modes exports.NONE=0;exports.DEFLATE=1;exports.INFLATE=2;exports.GZIP=3;exports.GUNZIP=4;exports.DEFLATERAW=5;exports.INFLATERAW=6;exports.UNZIP=7;/**```

I think this issue stems from the bmp-js package: https://github.com/shaozilee/bmp-js
The 0.0.1 version, which is the current latest on npm, has a bug. It's been fixed in the repo, I believe, but no new version has been published.

If you are only running locally, I found that simply using the latest commit on master branch of bmp-js eliminates the error. However, this doesn't solve the issue long term.

The latest version for the bmp-js package is now 0.0.2, please update the corresponding dependencies for this module

As for the v0.2.27 the bmp-js is still of version 0.0.1. Which is still throws the same error if we install jimp with npm install. Which is fine in local (by updating bmp-js), but needs some painful workarounds in the cloud.
So is the new version is comming soon? (it's kinda important to know for my project)

Hi @hanzenok.. you mentioned about workarounds in cloud. Can you give some more info on that? i am using heroku cloud to host my application.

@AbhishekBharadwajTME , I ended up using lwip. But the first workaround for jimp is to import v0.2.27 and update it's dependency bmp-js, to 0.0.2.

Another way is to import jimp from master:
{ "dependencies": { "jimp": "github:oliver-moran/jimp#master" } }

Good luck

closing in favor of #280

new versions should be fixed via #473

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chancein007 picture chancein007  路  5Comments

maqboolkhan picture maqboolkhan  路  5Comments

Favna picture Favna  路  4Comments

jBernavaPrah picture jBernavaPrah  路  4Comments

molipha picture molipha  路  6Comments