Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Errors when using webpack/Typescript #72

@Vivihung

Description

@Vivihung

I hit 2 errors in my project where we use webpack/Typescript.
(Note: I'm using the library in a web page)
The first error happened when building my project,

ERROR in ./~/pptxgenjs/dist/pptxgen.js

Module not found: Error: Cannot resolve module 'fs' in c:\myproj\node_modules\pptxgenjs\dist
 @ ./~/pptxgenjs/dist/pptxgen.js 2536:10-23

ERROR in ./~/image-size/lib/index.js

Module not found: Error: Cannot resolve module 'fs' in c:\myproj\node_modules\image-size\lib
 @ ./~/image-size/lib/index.js 3:9-22

ERROR in ./~/image-size/lib/types/tiff.js

Module not found: Error: Cannot resolve module 'fs' in c:\myproj\node_modules\image-size\lib\types
 @ ./~/image-size/lib/types/tiff.js 6:9-22

By referring to this post, I put the workaround in my webpack config
node: { fs: "empty" }

Then I hit another error when running my page in browser
Uncaught (in promise) TypeError: callback is not a function at eval (eval at <anonymous> (main.js:8466), <anonymous>:193:104)

It comes from this line of code in pptxgen.js
zip.generateAsync({type:'nodebuffer'}).then(function(content){ fs.writeFile(strExportName, content, callback(strExportName)); });

So, I comment it out as the following to bypass the error

/*
if ( NODEJS ) {
	zip.generateAsync({type:'nodebuffer'}).then(function(content){ fs.writeFile(strExportName, content, callback(strExportName)); });
}
else { */
	zip.generateAsync({type:'blob'}).then(function(content){ writeFileToBrowser(strExportName, content, callback); });
// }

Is there any way I can resolve the second error without changing PptxGenJS code?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions