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.

Cannot import `fontkit` from @pdf-lib/fontkit

See original GitHub issue

I am building an Angular project and trying to import fontkit as described in the README instruction. import fontkit from '@pdf-lib/fontkit' gives an error that says Module '"/node_modules/@pdf-lib/fontkit/fontkit"' has no default export. I tried using import * as fontkit from '@pdf-lib/fontkit', and this error does go away, but instead when I am registering this fontkit and using my custom font, it gives the error that says fontkit.create is not a function. What I want to achieve is to write my Chinese characters on the pdf. How should I import this fontkit and use it correctly?

image

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
Hopdingcommented, Sep 25, 2019

Hello @Pomelool! You can add "esModuleInterop": true or "allowSyntheticDefaultImports": true to the "compilerOptions" section of your Angular project’s tsconfig.json file. For example:

 {
   "compileOnSave": false,
   "compilerOptions": {
+    "esModuleInterop": true,
     "baseUrl": "./",
     "outDir": "./dist/out-tsc",

or

 {
   "compileOnSave": false,
   "compilerOptions": {
+    "allowSyntheticDefaultImports": true,
     "baseUrl": "./",
     "outDir": "./dist/out-tsc",

I hope this helps. Please let me know if you have any additional questions!

1reaction
alealimacommented, Apr 20, 2022

@btielen thanks a ton! Fixed everything for me as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@pdf-lib/fontkit - npm
An advanced font engine for Node and the browser. Latest version: 1.1.1, last published: 2 years ago. Start using @pdf-lib/fontkit in your ...
Read more >
Attempted import error: 'create' is not exported from 'fontkit ...
js Attempted import error: 'create' is not exported from 'fontkit' (imported as 'fontkit'). I tried to use different versions of this package, ...
Read more >
pdf-lib with fontkit won't allow custom fonts | Velo by Wix
All is working perfectly except that when trying to embed a custom font I get the error that fontkit.create() is not an existing...
Read more >
@pdf-lib/fontkit examples - CodeSandbox
Learn how to use @pdf-lib/fontkit by viewing and forking @pdf-lib/fontkit example apps on CodeSandbox.
Read more >
@pdf-lib/fontkit NPM | npm.io
import fontkit from '@pdf-lib/fontkit'; import fs from 'fs'; // open a font synchronously const fontData = fs.readFileSync('font.ttf'); const font ...
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