Pdfkit: Cannot resolve module 'fs'

Created on 10 Mar 2016  路  7Comments  路  Source: foliojs/pdfkit

Trying to build from webpack, I'm hitting a lot of dependencies on the node fs module, in js/image/jpeg.js, /js/font/dfont.js, png-js/png-node.js, and several more.

Most helpful comment

Got it building with these steps.

npm install transform-loader brfs --save

In webpack config module.loaders add

{ test: /pdfkit|png-js/, loader: "transform?brfs" },
{ test: /\.json$/, loader: "json" }

The font examples in the docs don't work because they try to read from the file system. Not sure if this is expected, or if there's a way to embed fonts in the browser bundle, or read from uri instead of file system.

All 7 comments

Got it building with these steps.

npm install transform-loader brfs --save

In webpack config module.loaders add

{ test: /pdfkit|png-js/, loader: "transform?brfs" },
{ test: /\.json$/, loader: "json" }

The font examples in the docs don't work because they try to read from the file system. Not sure if this is expected, or if there's a way to embed fonts in the browser bundle, or read from uri instead of file system.

With the latest create-react-app I've been getting this error:

alt-1

I'm not even playing with images or font yet. Just trying to get it to load the module..

Any ideas?

edit - (I tried

{ test: /pdfkit|png-js/, loader: "transform?brfs" },
{ test: /\.json$/, loader: "json" }

In webpack 2, I included the following in my webpack.config.js file:

module: {
  loaders: {
     { test: /(pdfkit|linebreak|fontkit|unicode|brotli|png-js).*\.js$/, loader: "transform-loader?brfs" }
  }
}

This worked, but I'm not sure if it handles everything.

@pboyer Thanks :) You have rescued me

Hi guys,
I use the library in MacOS and Linux with Webpack 1 the way suggested:

loaders: {
     { test: /(pdfkit|linebreak|fontkit|unicode|brotli|png-js).*\.js$/, loader: "transform-loader?brfs" }
  }

but the problem persists when trying to pack the project on a Windows 10 machine. Any ideas?

Webpack 1 is not supported anymore.

Here's a example with webpack 4: https://github.com/blikblum/pdfkit-webpack-example

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alFReD-NSH picture alFReD-NSH  路  4Comments

ehaubold picture ehaubold  路  5Comments

balsamiqMichele picture balsamiqMichele  路  4Comments

tm2josep picture tm2josep  路  5Comments

huy-nguyen picture huy-nguyen  路  4Comments