-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't resolve 'fs' in .../...node_modules\pdfkit\js' - webpack loader issue #659
Comments
@AionDev |
@dicbrus i used jsPdf but is not that powerful. Adding:
to my |
including the browser releases for pdfkit and blobstream worked for me
since they don't rely on fs |
I ran into the same problem and adding these 2 loaders into I didn't have to set {
module: {
rules: [
{
test: /node_modules\/(pdfkit|fontkit|png-js|linebreak|unicode-properties|brotli)\//,
loader: "transform-loader?brfs"
},
{
test: /node_modules\/unicode-properties.*\.json$/,
use: 'json-loader',
},
]
}
} |
@huy-nguyen Thanks for your help here.
This statement is not accurate. Although I actually did a lot of unnecessary research to "solve" this problem because I didn't read your response clearly enough and thought "I don't want browserify running too. That's crazy." But all along the answer was right here. Hahaha.
Also a note from
When I can, I'll try to hunt down the right place in the docs to add this and create a pull request. {
module: {
rules: [
{
test: /node_modules\/(pdfkit|fontkit|png-js|linebreak|unicode-properties|brotli)\//,
loader: "transform-loader?brfs"
},
{
test: /node_modules\/unicode-properties.*\.json$/,
use: 'json-loader',
},
]
}
} |
@skylize Actually what I posted wasn't enough. This is what I ended up with for webpack loaders config: [
{
// These are all pdfkit-related packages that need to be ran through browserify:
test: /node_modules\/(pdfkit|png-js|linebreak|unicode-properties|brotli)\//,
loader: 'transform-loader?brfs',
},
// `fontkit` needs special treatment because it needs both `browserify` and `babelify`:
{
test: /node_modules\/fontkit\//,
use: [
{loader: 'transform-loader?brfs'},
{
loader: 'babel-loader',
options: {
presets: ['env'],
plugins: ['transform-decorators-legacy', 'transform-class-properties'],
},
},
],
},
{
test: /node_modules\/(unicode-properties|fontkit).*\.json$/,
use: 'json-loader',
},
] And I had to set this alias in webpack: alias: {
util$: path.resolve(__dirname, 'node_modules/util'),
}, And pin down the version of the {
"util": "0.10.0"
} |
@huy-nguyen Hmmm. Interesting. I got mine up and running just fine only your first example. But I'm not doing anything special with fonts. I wonder if it matters what features you are using here. ??? Still the comment is incorrect in your newer example. We don't need to "browserify" anything. We only need to handle It is completely its own small tool that just happened to be initially created to fill a need with browserify. Browserify did not handle calls to |
In case anyone is still confused by the above conversation, I made a minimal example of using |
In my case the solution was to use the approach suggested by Hecklit commented on 9 Aug 2017 |
@huy-nguyen i'm still getting the the repo example doesn't have the babel stuff in your example here, is there something with that? |
got it to work with matching versions, thanks! |
ok, actually, it starts to try and use fs to load fonts if you specify |
For the record I summarize what did the trick for me. I started my project with Vue.js starter project webpack. In
Naturally, I added
Then, I added the following
Finally, I fixed the webpack config in the file
In one of my source files I included PDFKit using
Finally my project built and let me use PDFKit without dirty workarounds! :) |
Does anyone know whether PDFKit is compatible with WebPack version 4? The previous solutions do not work anymore ... I'm getting
for pdfkit/js/document.js, pdfkit/js/image.js, pdfkit/js/font/afm.js, png-js/png-node.js. I have no clue what has changed from WebPack 3 to WebPack 4 ... If anyone has got this working with WebPack 4.0, I'd very much appreciate it. |
See https://github.com/blikblum/pdfkit-webpack-example for a complete example |
My webpack.config.js looks like this:
In my
app.js
i have just this line: - nothing else.const PDFDocument = require ('pdfkit');
Which gives me the following errors:
I can't get this library working with webpack in any way. Please can you give me an example that uses webpack instead of broweseify?
The text was updated successfully, but these errors were encountered: