johannschopplich / pdfjs-serverless

🪭 Serverless build of PDF.js for Deno, workers, and other nodeless environments
MIT License
65 stars 2 forks source link

Error: No "exports" main defined in package.json #3

Open Soviut opened 6 days ago

Soviut commented 6 days ago

Node: v20.18.0 pdfjs-serverless: 0.6.0

I've used pdfjs-serverless in another project and it worked fine. However, when I installed it in a new project I got the following error. The previous project used pdfjs-serverless@0.4.2, but switching the new project to that version gave the same error.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/ian/projects/talint-match-middleware/node_modules/pdfjs-serverless/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:304:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:594:13)
    at resolveExports (node:internal/modules/cjs/loader:634:36)
    at Module._findPath (node:internal/modules/cjs/loader:724:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1211:27)
    at nextResolveSimple (/home/ian/projects/talint-match-middleware/node_modules/tsx/dist/register-DpmFHar1.cjs:3:942)
    at /home/ian/projects/talint-match-middleware/node_modules/tsx/dist/register-DpmFHar1.cjs:2:2550
    at /home/ian/projects/talint-match-middleware/node_modules/tsx/dist/register-DpmFHar1.cjs:2:1624
    at resolveTsPaths (/home/ian/projects/talint-match-middleware/node_modules/tsx/dist/register-DpmFHar1.cjs:3:760)
    at /home/ian/projects/talint-match-middleware/node_modules/tsx/dist/register-DpmFHar1.cjs:3:1038 {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
johannschopplich commented 6 days ago

This package is ESM only. I'm not sure if converting the PDF.js bundle to CJS is a viable option. I would have to investigate.

Can I migrate my project to ESM? The ecosystem is slowly but steadily migrating from CJS to ESM, so I highly recommend following this approach. At least if your project allows it. 🙂

Soviut commented 6 days ago

Perhaps I just need to update my tsconfig.json to something other than

"module": "commonjs"