Hopding/pdf-lib

ES import with typescript results in Could not resolve "pdf-lib"

maxschulmeister opened this issue · 1 comments

What were you trying to do?

I'm simply trying to import "pdf-lib" for usage in a figma plugin.

How did you attempt to do it?

import { PDFDocument } from "pdf-lib";

What actually happened?

ts outputs Could not resolve "pdf-lib"

What did you expect to happen?

a clean import

How can we reproduce the issue?

tsconfig.json

{
  "compilerOptions": {
   "esModuleInterop": true,
    "isolatedModules": true,
    "jsx": "react",
    "jsxFactory": "h",
    "lib": ["DOM", "ES2020"],
    "module": "ES2020",
    "moduleResolution": "Node",
    "strict": true,
    "typeRoots": ["node_modules/@figma", "node_modules/@types"],
    "paths": {
      "@/*": ["./src/*"]
    },
    "target": "es2017"
  },
  "include": ["src/**/*.ts", "src/**/*.tsx"]
}

Version

latest

What environment are you running pdf-lib in?

Browser

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

this was an issue related to esbuild and its "platform" parameter.

setting mainFields for esbuild buildOptions to
mainFields: ["module", "main", "browser"],

fixed the issue.

save to close this.