question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using pdfkit: "Error: ENOENT: no such file or directory, open '//data.trie'"

See original GitHub issue

I am trying to switch from serverless-webpack to serverless-bundle, but I cannot get it to work with pdfkit. I get the following error when trying to invoke my lambda:

Serverless: Bundling with Webpack...
{ Error: ENOENT: no such file or directory, open '//data.trie'
    at Object.openSync (fs.js:438:3)
    at Object.readFileSync (fs.js:343:35)
    at Module.<anonymous> (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/mnt/c/dev/photobook-api/services/photobook-api/node_modules/unicode-properties/unicode-properties.es.js:137:30)
    at Module.../../../services/photobook-api/node_modules/unicode-properties/unicode-properties.es.js (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/generate-preview.js:47407:30)
    at __webpack_require__ (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/webpack/bootstrap:19:1)
    at Object.<anonymous> (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/mnt/c/dev/photobook-api/services/photobook-api/node_modules/fontkit/index.js:24:31)
    at Object.../../../services/photobook-api/node_modules/fontkit/index.js (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/generate-preview.js:37486:30)
    at __webpack_require__ (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/webpack/bootstrap:19:1)
    at Module.<anonymous> (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/mnt/c/dev/photobook-api/services/photobook-api/node_modules/pdfkit/js/pdfkit.es5.js:1:1)
    at Module.../../../services/photobook-api/node_modules/pdfkit/js/pdfkit.es5.js (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/generate-preview.js:44528:30)
    at __webpack_require__ (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/webpack/bootstrap:19:1)
    at Module.../../../services/photobook-api/src/util/PreviewBase.js (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/generate-preview.js:48211:64)
    at __webpack_require__ (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/webpack/bootstrap:19:1)
    at Module.../../../services/photobook-api/src/util/BookPreview.js (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/generate-preview.js:47669:70)
    at __webpack_require__ (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/webpack/bootstrap:19:1)
    at Module.../../../services/photobook-api/src/generate-preview.js (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/generate-preview.js:47567:75)
    at __webpack_require__ (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/webpack/bootstrap:19:1)
    at /mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/webpack:/webpack/bootstrap:83:1       at Object.<anonymous> (/mnt/c/dev/photobook-api/services/photobook-api/.webpack/generate-preview/src/generate-preview.js:87:10)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at AwsInvokeLocal.invokeLocalNodeJs (/usr/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:616:33)     at AwsInvokeLocal.invokeLocal (/usr/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:167:19)           at AwsInvokeLocal.tryCatcher (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)         at Promise._settlePromiseFromHandler (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)        at Promise._settlePromiseCtx (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:641:10)     at _drainQueueStep (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '//data.trie' }

I was able to use pdfkit with no problems when using serverless-webpack with the following webpack.config.js:

const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");

module.exports = {
  entry: slsw.lib.entries,
  target: "node",
  // Generate sourcemaps for proper error messages
  devtool: 'source-map',
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  externals: [nodeExternals()],
  mode: slsw.lib.webpack.isLocal ? "development" : "production",
  optimization: {
    // We do not want to minimize our code.
    minimize: false
  },
  performance: {
    // Turn off size warnings for entry points
    hints: false
  },
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  }
};

How can I configure serverless-bundle so that pdfkit works? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
carlcheel-sagecommented, Jul 30, 2020

This issue can be resolved by adding pdfkit to the serverless-bundle externals config.

Example

custom:
  bundle:
    externals: # Set non Webpack compatible packages as externals
      - pdfkit # They'll be included in the node_modules/

Note: Sometimes 3rd party modules aren’t compatible with webpack for various reasons.

I believe this was working with serverless-webpack directly due to using webpack-node-externals.

Based on this, I believe this issue can be closed @jayair.

0reactions
jayaircommented, Aug 17, 2020

@carlcheel-sage Awesome. Thanks for looking into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no such file or directory, open '//data.trie' · Issue #990 · foliojs ...
How to solve this? Error: ENOENT: no such file or directory, open '//data.trie'. Code sample. const PDFDocument = require('pdfkit');
Read more >
pdfkit on JS/TS Lambda with CDK Error: ENOENT: no such file ...
pdfkit was not loaded properly in the lambda function. I solved this by following this advice for adding external dependencies to a lambda ......
Read more >
Using PDFKit in a netlify function - Support
I'm trying to build some functions that return PDFs using PDFkit. ... Error: ENOENT: no such file or directory, open ...
Read more >
ENOENT: no such file or directory, open '//data.trie'
ENOENT : no such file or directory, open '//data.trie' ; 1. custom: ; 2. bundle: # For serverless fix ; 3. externals: #...
Read more >
wave My colleague is having problems with pdfkit library an | Sst ...
Thanks! `Error: ENOENT: no such file or directory, open '/Users/.../pms-integrations-v2/services/hsk/.build/src/cron/data.trie'
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found