Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.89k stars 656 forks source link

Error: An accessor cannot be declared in an ambient context #308

Closed paupizaru closed 4 years ago

paupizaru commented 4 years ago

Hello, I'm having an issue when compiling my project:

Error

error

I deleted the node_modules folder to do a "clean" npm install and then I installed -> npm i pdf-lib@1.2.0 (we were using 1.2.1 so we tried using 1.2.0 and "it worked" but then we couldn't login into our project even with the server running).

Then one of our teammates upgraded the Angular version from 7 to 8 and the error was still there.

Hopding commented 4 years ago

This seems to be due to https://github.com/microsoft/TypeScript/issues/33939.

Hopding commented 4 years ago

Looks like other libraries have run into this issue as well, e.g. nest:

madmansn0w commented 4 years ago

Any solution to this? Dealing with it as well. Edit: So I went ahead and upgraded Typescript to ^3.7.4 (Angular Compiler ~8.2.3) which meant that I needed to ignore the typescript version. Doesn't seem to have made any breaking changes. I also had to update @types/nodes in the process. Followed this thread starting with this comment and then this comment It's a workaround, but I'm not certain if things will break just yet.

Hopding commented 4 years ago

It seems the best solution at the moment is to update your version of TypeScript to 3.7.x. But it would be ideal if pdf-lib didn't require you to do this. It looks like it may be possible to produce backwards compatible .d.ts files using https://github.com/sandersn/downlevel-dts (per https://github.com/microsoft/TypeScript/issues/33939#issuecomment-573134649). Otherwise we'll have to downgrade our version of typescript from 3.7 to 3.6.

paupizaru commented 4 years ago

Hi, thanks for answering you all, I haven't upgraded my Angular compiler version yet, it is still ~7.1.0, so I can only use Typescript ~3.2.4, my teammates tell me that in order to use Typescript 3.7.x I have to upgrade Angular from 7 to 8 first, I will let you know If by doing so my problem is solved.

paupizaru commented 4 years ago

Hello again, It seems that as you both said the real solution is to upgrade Typescript version. We can't upgrade Angular at this moment so we decided to freeze the pdf-lib version in 1.2.0 which is working for us (the login bug I mentioned when I opened the issue had nothing to do with this, so we fixed it and know works with pdf-lib 1.2.0 but not with 1.2.1).

Thank you everyone

Hopding commented 4 years ago

Version 1.4.0 is now published. It contains additional TypeScript declarations for older version of TypeScript that should resolve this issue. The full release notes are available here.

You can install this new version with npm:

npm install pdf-lib@1.4.0

It's also available on unpkg:

As well as jsDelivr: