jsPDF: WebPack - Issue : Error: Can't resolve 'fs'

Thank you for submitting an issue to jsPDF. Please read carefully.

Are you using the latest version of jsPDF?

The issue occurs after upgrading from 1.3.5 to 1.4.0 (npm version). My project uses Webpack to build a bundle.

Have you tried using jspdf.debug.js?

I did. the error occurs on line 5387:14-27 (var fs = require('fs');)

  		var nodeJSMethod = function nodeJSMethod(path, sync, callback) {
  			sync = sync || true;
  			var fs = require('fs');
  			if (sync === true) {
  				var data = fs.readFileSync(path).toString();
  				return data;
  			} else {
  				fs.readFile('image.jpg', function (err, data) {
  					callback(data);
  				});
  			}
  		};

Steps to reproduce

It happens when I use webpack to build my project

Ideally a link too. Try fork this http://jsbin.com/rilace/edit?html,js,output

What I saw

ERROR in ./node_modules/jspdf/dist/jspdf.debug.js
Module not found: Error: Can't resolve 'fs' in '.\node_modules\jspdf\dist'
 @ ./node_modules/jspdf/dist/jspdf.debug.js 5387:14-27

What I expected

Expected webpack to complete without error as it did in v1.3.5

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 17
  • Comments: 25 (1 by maintainers)

Most upvoted comments

Same issue. We cannot update our projects to Angular6 because of this issue. Would appreciate any workaround.

@arasabbasi At the moment I can’t get angular to work with this version, and I don’t want to eject my project into a webpack one. It’s possible it doesn’t work anymore. If anyone has a solution, then please post here.

for webpack you can use

node: {
   fs: 'empty'
},

removed with Commit 7a1089a

Will be part of v. 1.4.1

v. 1.4.1 released

I think you should release a build with this fix if possible as most of the people use webpack and this is a blocker.

Thank you for the work so far 🚀