vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
723 stars 178 forks source link

[ERROR] Could not find a declaration file for module 'node-signpdf'. '(...)node_modules/node-signpdf/dist/signpdf.js' implicitly has an 'any' type. Try `npm install @types/node-signpdf` if it exists or add a new declaration (.d.ts) file containing `declare module 'node-signpdf';`ts(7016) #20

Closed marcioamr closed 5 years ago

marcioamr commented 5 years ago

I got this error when I tried to run this code:

import signer from 'node-signpdf';

const PATH_TO_PDF_FILE = "test.pdf"; 
const PATH_TO_P12_CERTIFICATE = "key.p12";

const signedPdf = signer.sign(
  fs.readFileSync(PATH_TO_PDF_FILE),
  fs.readFileSync(PATH_TO_P12_CERTIFICATE),
);
/(...)/app.js:1
(function (exports, require, module, __filename, __dirname) { import signer from 'node-signpdf';
                                                                     ^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
vbuch commented 5 years ago

Havent tried with typescript. There are no definitions (d.ts).

rcarauta commented 5 years ago

I try to use in javascript app with node but has the same error

vbuch commented 5 years ago

You are trying to go with JS but you are getting a TS error? I don't get it. Node does not support imports by default if you mean that you are having the error from the description and not the one from the title. And you may be trying to load the code from src when you should work with the one in dist

vbuch commented 5 years ago

No activity. Closing.

finsfera0 commented 2 years ago

update, the same error.

rooty@linux:~/node_modules/node-signpdf$ node src/signpdf.test.js 
[sudo] password for rooty: 
/home/rooty/node_modules/node-signpdf/src/signpdf.test.js:1
import PDFDocument from 'pdfkit';
       ^^^^^^^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Thanks.

cpimenta-apsoftware commented 2 years ago

removing "strict": true in tsconfig.json worked for me