PJD
PJD

Reputation: 101

SyntaxError: Unexpected token '||=' on import of pdfjs-dist

Trying to use pdfjs-dist in node js app

Steps:

created new node js app (module) then:-

npm i pdfjs-dist

package.json is:-

"name": "testpdf",
  "version": "1.0.0",
  "description": "pdf test",
  "main": "testpdf.js",
  "type": "module",
  "scripts": {
    "start": "node testpdf.js"
  },
  "dependencies": {
    "pdfjs-dist": "^2.13.216"
  }
}

1 line app (testpdf.js) is

import pdfjs from 'pdfjs-dist'

Get this error with the import:

D:\dev\pdf\node_modules\pdfjs-dist\build\pdf.js:1707 return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex); ^^^

SyntaxError: Unexpected token '||=' at wrapSafe (internal/modules/cjs/loader.js:979:16) at Module._compile (internal/modules/cjs/loader.js:1027:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at ModuleWrap. (internal/modules/esm/translators.js:199:29) at ModuleJob.run (internal/modules/esm/module_job.js:152:23) at async Loader.import (internal/modules/esm/loader.js:166:24) at async Object.loadESM (internal/process/esm_loader.js:68:5) PS D:\dev\pdf>

If I look at node_modules\pdfjs-dist\build\pdf.js there are multiple instances of use of this operator "||="

I'm no javascript expert but from what I know this is not a valid opertaor and node v14.15.4 doesn't seem to think it is either.

Note this package version (pdfjs-dist 2.13.216) has been available for two months and can't find a similar issue on the net so guessing I am doing something wrong...

Any ideas?

Upvotes: 4

Views: 4135

Answers (2)

rrrokhtar
rrrokhtar

Reputation: 1113

You can also use their legacy build through (which is compatible with node)

const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");

pdfjs version: (3.2.146)
node version: (14.21.3)

Install

npm i [email protected]

Upvotes: 0

PJD
PJD

Reputation: 101

As was on and old version of NodeJS I upgraded to the latest version v18.1.0 and this cleared the issue

Upvotes: 4

Related Questions