Open
Description
What were you trying to do?
run tsc
after importing pdf-lib
into my node project
How did you attempt to do it?
npm i pdf-lib@latest
import { PDFDocument } from 'pdf-lib';
const pdfDoc = await PDFDocument.load(
file_path,
{ updateMetadata: false },
);
What actually happened?
Compilation failed with errors:
node_modules/pdf-lib/src/api/PDFPageOptions.ts:1:23 - error TS2307: Cannot find module 'src/api/colors' or its corresponding type declarations.
1 import { Color } from 'src/api/colors';
~~~~~~~~~~~~~~~~
node_modules/pdf-lib/src/api/PDFPageOptions.ts:2:21 - error TS2307: Cannot find module 'src/api/PDFFont' or its corresponding type declarations.
2 import PDFFont from 'src/api/PDFFont';
~~~~~~~~~~~~~~~~~
node_modules/pdf-lib/src/api/PDFPageOptions.ts:3:26 - error TS2307: Cannot find module 'src/api/rotations' or its corresponding type declarations.
3 import { Rotation } from 'src/api/rotations';
~~~~~~~~~~~~~~~~~~~
node_modules/pdf-lib/src/api/PDFPageOptions.ts:4:30 - error TS2307: Cannot find module 'src/api/operators' or its corresponding type declarations.
4 import { LineCapStyle } from 'src/api/operators';
~~~~~~~~~~~~~~~~~~~
Found 4 errors.
What did you expect to happen?
Compile successfully.
How can we reproduce the issue?
I'm using this tsconfig.json
{
"compilerOptions": {
"incremental": true,
"target": "ES2019",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"outDir": "./build",
"removeComments": true,
"strict": true,
"baseUrl": "./",
"typeRoots": [
"./typings",
"./node_modules/@types"
],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"exclude": ["node_modules", "test", "**/*.spec.ts", "build"]
}
Version
1.17.1
What environment are you running pdf-lib in?
Node
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
in pdf-lib
's tsconfig.json
, "moduleResolution"
is configured as "node"
, but the relative imports to project root are used, like: 'src/api/colors'
(see: https://github.com/Hopding/pdf-lib/blob/master/src/api/PDFPageOptions.ts)
I'm using node
moduleResolution in my project and pdf-lib
seems to follow classic
moduleResolution strategy. Is there a way out to solve this issue?