Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use Pdfme on nodejs v20 #447

Open
slim-hmidi opened this issue Mar 17, 2024 · 2 comments
Open

Can't use Pdfme on nodejs v20 #447

slim-hmidi opened this issue Mar 17, 2024 · 2 comments

Comments

@slim-hmidi
Copy link

Describe the bug

I created an express application using Node.js v20, I want to generate a pdf through the data sent to the api. When I run the server I got many typescript errors related to antd module.

To Reproduce

I created a template and I installed @pdfme/generator and @pdfme/common:

import { generate } from '@pdfme/generator';
import { template } from '@pdfme/common';
import {writeFile} from 'fs/promises';
import path from 'path';
const generateInquiryPdf = async (template: Template, inputs: Record<string, string>[]) => {
    const generatedPdf = await generate({ template, inputs })
    await writeFile(path.join(__dirname, `inquiry.pdf`), generatedPdf);
}

Expected behavior

It should generate a pdf.

Your Environment

- pdfme package(@pdfme/generator): 3.4.0
- pdfme version: 3.4.0
- Operating system: macOs
- Node.js version : v20.10.0

Your Error Log

node_modules/@ant-design/cssinjs/lib/StyleContext.d.ts:25:27 - error TS2304: Cannot find name 'ShadowRoot'.

25     container?: Element | ShadowRoot;
                             ~~~~~~~~~~

node_modules/@pdfme/common/dist/types/src/types.d.ts:65:26 - error TS2307: Cannot find module 'pdfjs-dist/legacy/build/pdf.js' or its corresponding type declarations.

65     pdfJs: typeof import('pdfjs-dist/legacy/build/pdf.js');
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@rc-component/tour/es/hooks/useTarget.d.ts:13:127 - error TS2304: Cannot find name 'ScrollIntoViewOptions'.

13 export default function useTarget(target: TourStepInfo['target'], open: boolean, gap?: Gap, scrollIntoViewOptions?: boolean | ScrollIntoViewOptions): [PosInfo, HTMLElement];
                                                                                                                                 ~~~~~~~~~~~~~~~~~~~~~

node_modules/@rc-component/tour/es/interface.d.ts:20:39 - error TS2304: Cannot find name 'ScrollIntoViewOptions'.

20     scrollIntoViewOptions?: boolean | ScrollIntoViewOptions;
                                         ~~~~~~~~~~~~~~~~~~~~~

node_modules/@rc-component/tour/es/interface.d.ts:61:39 - error TS2304: Cannot find name 'ScrollIntoViewOptions'.

61     scrollIntoViewOptions?: boolean | ScrollIntoViewOptions;
                                         ~~~~~~~~~~~~~~~~~~~~~

node_modules/@rc-component/trigger/lib/index.d.ts:7:17 - error TS2552: Cannot find name 'VoidFunction'. Did you mean 'Function'?

7     forceAlign: VoidFunction;
                  ~~~~~~~~~~~~

  node_modules/typescript/lib/lib.es5.d.ts:319:13
    319 declare var Function: FunctionConstructor;
                    ~~~~~~~~
    'Function' is declared here.

node_modules/antd/es/_util/responsiveObserver.d.ts:10:18 - error TS2304: Cannot find name 'MediaQueryList'.

10             mql: MediaQueryList;
                    ~~~~~~~~~~~~~~

node_modules/antd/es/_util/responsiveObserver.d.ts:11:31 - error TS2304: Cannot find name 'MediaQueryList'.

11             listener: ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | null;
                                 ~~~~~~~~~~~~~~

node_modules/antd/es/_util/responsiveObserver.d.ts:11:51 - error TS2304: Cannot find name 'MediaQueryListEvent'.

11             listener: ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | null;
                                                     ~~~~~~~~~~~~~~~~~~~

node_modules/antd/es/affix/index.d.ts:12:20 - error TS2304: Cannot find name 'Window'.

12     target?: () => Window | HTMLElement | null;
                      ~~~~~~

node_modules/antd/es/anchor/Anchor.d.ts:7:45 - error TS2304: Cannot find name 'Window'.

7 export type AnchorContainer = HTMLElement | Window;
                                              ~~~~~~

node_modules/antd/es/back-top/index.d.ts:5:34 - error TS2304: Cannot find name 'Window'.

5     target?: () => HTMLElement | Window | Document;
                                   ~~~~~~

node_modules/antd/es/config-provider/index.d.ts:14:46 - error TS2304: Cannot find name 'Window'.

14     getTargetContainer?: () => HTMLElement | Window;
                                                ~~~~~~

node_modules/antd/es/float-button/interface.d.ts:46:34 - error TS2304: Cannot find name 'Window'.

46     target?: () => HTMLElement | Window | Document;
                                    ~~~~~~

node_modules/antd/es/input/Input.d.ts:6:44 - error TS2304: Cannot find name 'FocusOptions'.

6 export interface InputFocusOptions extends FocusOptions {
                                             ~~~~~~~~~~~~

node_modules/antd/es/menu/index.d.ts:15:23 - error TS2304: Cannot find name 'FocusOptions'.

15     focus: (options?: FocusOptions) => void;
                         ~~~~~~~~~~~~

node_modules/antd/es/message/interface.d.ts:27:68 - error TS2552: Cannot find name 'VoidFunction'. Did you mean 'Function'?

27 export type TypeOpen = (content: JointContent, duration?: number | VoidFunction, // Also can use onClose directly
                                                                      ~~~~~~~~~~~~

  node_modules/typescript/lib/lib.es5.d.ts:319:13
    319 declare var Function: FunctionConstructor;
                    ~~~~~~~~
    'Function' is declared here.

node_modules/antd/es/message/interface.d.ts:28:11 - error TS2552: Cannot find name 'VoidFunction'. Did you mean 'Function'?

28 onClose?: VoidFunction) => MessageType;
             ~~~~~~~~~~~~

  node_modules/typescript/lib/lib.es5.d.ts:319:13
    319 declare var Function: FunctionConstructor;
                    ~~~~~~~~
    'Function' is declared here.

node_modules/antd/es/message/useMessage.d.ts:4:20 - error TS2304: Cannot find name 'VoidFunction'.

4     onAllRemoved?: VoidFunction;
                     ~~~~~~~~~~~~

node_modules/antd/es/modal/useModal/index.d.ts:4:57 - error TS2304: Cannot find name 'VoidFunction'.

4     then<T>(resolve: (confirmed: boolean) => T, reject: VoidFunction): Promise<T>;
                                                          ~~~~~~~~~~~~

node_modules/antd/es/notification/interface.d.ts:39:40 - error TS2304: Cannot find name 'ShadowRoot'.

39     getContainer?: () => HTMLElement | ShadowRoot;
                                          ~~~~~~~~~~

node_modules/antd/es/notification/interface.d.ts:50:40 - error TS2304: Cannot find name 'ShadowRoot'.

50     getContainer?: () => HTMLElement | ShadowRoot;
                                          ~~~~~~~~~~

node_modules/antd/es/notification/useNotification.d.ts:4:20 - error TS2304: Cannot find name 'VoidFunction'.

4     onAllRemoved?: VoidFunction;
                     ~~~~~~~~~~~~

node_modules/antd/es/tooltip/index.d.ts:12:22 - error TS2304: Cannot find name 'VoidFunction'.

12     forcePopupAlign: VoidFunction;
                        ~~~~~~~~~~~~

node_modules/antd/es/tooltip/index.d.ts:13:17 - error TS2304: Cannot find name 'VoidFunction'.

13     forceAlign: VoidFunction;
                   ~~~~~~~~~~~~

node_modules/antd/es/watermark/index.d.ts:10:17 - error TS2304: Cannot find name 'CanvasFillStrokeStyles'.

10         color?: CanvasFillStrokeStyles['fillStyle'];
                   ~~~~~~~~~~~~~~~~~~~~~~

node_modules/antd/es/watermark/index.d.ts:15:21 - error TS2304: Cannot find name 'CanvasTextAlign'.

15         textAlign?: CanvasTextAlign;
                       ~~~~~~~~~~~~~~~

node_modules/compute-scroll-into-view/dist/index.d.ts:14:11 - error TS2304: Cannot find name 'ScrollLogicalPosition'.

14   block?: ScrollLogicalPosition
             ~~~~~~~~~~~~~~~~~~~~~

node_modules/compute-scroll-into-view/dist/index.d.ts:19:12 - error TS2304: Cannot find name 'ScrollLogicalPosition'.

19   inline?: ScrollLogicalPosition
              ~~~~~~~~~~~~~~~~~~~~~

node_modules/form-render/lib/type.d.ts:291:52 - error TS2339: Property 'validateMessages' does not exist on type 'FormConfig | undefined'.

291     validateMessages?: ConfigProviderProps['form']['validateMessages'];
                                                       ~~~~~~~~~~~~~~~~~~

node_modules/rc-checkbox/es/index.d.ts:12:23 - error TS2304: Cannot find name 'FocusOptions'.

12     focus: (options?: FocusOptions) => void;
                         ~~~~~~~~~~~~

node_modules/rc-drawer/lib/DrawerPanel.d.ts:3:12 - error TS2304: Cannot find name 'VoidFunction'.

3     focus: VoidFunction;
             ~~~~~~~~~~~~

node_modules/rc-image/lib/interface.d.ts:13:77 - error TS2304: Cannot find name 'VoidFunction'.

13 export type RegisterImage = (id: string, data: PreviewImageElementProps) => VoidFunction;
                                                                               ~~~~~~~~~~~~

node_modules/rc-input/lib/utils/commonUtils.d.ts:6:44 - error TS2304: Cannot find name 'FocusOptions'.

6 export interface InputFocusOptions extends FocusOptions {
                                             ~~~~~~~~~~~~

node_modules/rc-mentions/lib/Mentions.d.ts:44:12 - error TS2304: Cannot find name 'VoidFunction'.

44     focus: VoidFunction;
              ~~~~~~~~~~~~

node_modules/rc-mentions/lib/Mentions.d.ts:45:11 - error TS2304: Cannot find name 'VoidFunction'.

45     blur: VoidFunction;
             ~~~~~~~~~~~~

node_modules/rc-menu/lib/interface.d.ts:77:23 - error TS2304: Cannot find name 'FocusOptions'.

77     focus: (options?: FocusOptions) => void;
                         ~~~~~~~~~~~~

node_modules/rc-notification/lib/interface.d.ts:19:15 - error TS2304: Cannot find name 'VoidFunction'.

19     onClose?: VoidFunction;
                 ~~~~~~~~~~~~

node_modules/rc-picker/lib/interface.d.ts:205:89 - error TS2552: Cannot find name 'VoidFunction'. Did you mean 'Function'?

205 export type LegacyOnKeyDown = (event: React.KeyboardEvent<HTMLElement>, preventDefault: VoidFunction) => void;
                                                                                            ~~~~~~~~~~~~

  node_modules/typescript/lib/lib.es5.d.ts:319:13
    319 declare var Function: FunctionConstructor;
                    ~~~~~~~~
    'Function' is declared here.

node_modules/rc-picker/lib/interface.d.ts:294:23 - error TS2304: Cannot find name 'FocusOptions'.

294     focus: (options?: FocusOptions) => void;
                          ~~~~~~~~~~~~

node_modules/rc-picker/lib/interface.d.ts:295:11 - error TS2304: Cannot find name 'VoidFunction'.

295     blur: VoidFunction;
              ~~~~~~~~~~~~

node_modules/rc-picker/lib/interface.d.ts:298:31 - error TS2304: Cannot find name 'FocusOptions'.

298     focus: (index?: number | (FocusOptions & {
                                  ~~~~~~~~~~~~

node_modules/rc-picker/lib/interface.d.ts:327:15 - error TS2304: Cannot find name 'VoidFunction'.

327     onSubmit: VoidFunction;
                  ~~~~~~~~~~~~

node_modules/rc-picker/lib/interface.d.ts:334:14 - error TS2304: Cannot find name 'VoidFunction'.

334     onClear: VoidFunction;
                 ~~~~~~~~~~~~

node_modules/rc-picker/lib/interface.d.ts:341:20 - error TS2304: Cannot find name 'VoidFunction'.

341     onInputChange: VoidFunction;
                       ~~~~~~~~~~~~

node_modules/rc-picker/lib/PickerPanel/index.d.ts:40:18 - error TS2430: Interface 'SinglePickerPanelProps<DateType>' incorrectly extends interface 'BasePickerPanelProps<DateType>'.
  Types of property 'defaultValue' are incompatible.
    Type 'DateType | null | undefined' is not assignable to type 'DateType | undefined'.
      Type 'null' is not assignable to type 'DateType | undefined'.

40 export interface SinglePickerPanelProps<DateType extends object = any> extends BasePickerPanelProps<DateType> {
                    ~~~~~~~~~~~~~~~~~~~~~~

node_modules/rc-rate/lib/Rate.d.ts:23:12 - error TS2304: Cannot find name 'VoidFunction'.

23     focus: VoidFunction;
              ~~~~~~~~~~~~

node_modules/rc-rate/lib/Rate.d.ts:24:11 - error TS2304: Cannot find name 'VoidFunction'.

24     blur: VoidFunction;
             ~~~~~~~~~~~~

node_modules/rc-select/lib/BaseSelect.d.ts:19:23 - error TS2304: Cannot find name 'FocusOptions'.

19     focus: (options?: FocusOptions) => void;
                         ~~~~~~~~~~~~

node_modules/rc-table/lib/interface.d.ts:183:26 - error TS2304: Cannot find name 'Window'.

183     getContainer?: () => Window | HTMLElement;
                             ~~~~~~

node_modules/rc-tooltip/lib/Tooltip.d.ts:31:17 - error TS2304: Cannot find name 'VoidFunction'.

31     forceAlign: VoidFunction;
                   ~~~~~~~~~~~~

node_modules/rc-upload/lib/interface.d.ts:23:72 - error TS2304: Cannot find name 'XMLHttpRequest'.

23     onSuccess?: (response: Record<string, unknown>, file: RcFile, xhr: XMLHttpRequest) => void;
                                                                          ~~~~~~~~~~~~~~

node_modules/rc-upload/lib/interface.d.ts:42:54 - error TS2304: Cannot find name 'ProgressEvent'.

42 export interface UploadProgressEvent extends Partial<ProgressEvent> {
                                                        ~~~~~~~~~~~~~

node_modules/rc-upload/lib/interface.d.ts:54:44 - error TS2304: Cannot find name 'ProgressEvent'.

54     onError?: (event: UploadRequestError | ProgressEvent, body?: T) => void;
                                              ~~~~~~~~~~~~~

node_modules/rc-upload/lib/interface.d.ts:55:33 - error TS2304: Cannot find name 'XMLHttpRequest'.

55     onSuccess?: (body: T, xhr?: XMLHttpRequest) => void;
                                   ~~~~~~~~~~~~~~

node_modules/scroll-into-view-if-needed/dist/index.d.ts:76:14 - error TS2304: Cannot find name 'ScrollBehavior'.

76   behavior?: ScrollBehavior
                ~~~~~~~~~~~~~~


Found 56 errors in 37 files.

Errors  Files
     1  node_modules/@ant-design/cssinjs/lib/StyleContext.d.ts:25
     1  node_modules/@pdfme/common/dist/types/src/types.d.ts:65
     1  node_modules/@rc-component/tour/es/hooks/useTarget.d.ts:13
     2  node_modules/@rc-component/tour/es/interface.d.ts:20
     1  node_modules/@rc-component/trigger/lib/index.d.ts:7
     3  node_modules/antd/es/_util/responsiveObserver.d.ts:10
     1  node_modules/antd/es/affix/index.d.ts:12
     1  node_modules/antd/es/anchor/Anchor.d.ts:7
     1  node_modules/antd/es/back-top/index.d.ts:5
     1  node_modules/antd/es/config-provider/index.d.ts:14
     1  node_modules/antd/es/float-button/interface.d.ts:46
     1  node_modules/antd/es/input/Input.d.ts:6
     1  node_modules/antd/es/menu/index.d.ts:15
     2  node_modules/antd/es/message/interface.d.ts:27
     1  node_modules/antd/es/message/useMessage.d.ts:4
     1  node_modules/antd/es/modal/useModal/index.d.ts:4
     2  node_modules/antd/es/notification/interface.d.ts:39
     1  node_modules/antd/es/notification/useNotification.d.ts:4
     2  node_modules/antd/es/tooltip/index.d.ts:12
     2  node_modules/antd/es/watermark/index.d.ts:10
     2  node_modules/compute-scroll-into-view/dist/index.d.ts:14
     1  node_modules/form-render/lib/type.d.ts:291
     1  node_modules/rc-checkbox/es/index.d.ts:12
     1  node_modules/rc-drawer/lib/DrawerPanel.d.ts:3
     1  node_modules/rc-image/lib/interface.d.ts:13
     1  node_modules/rc-input/lib/utils/commonUtils.d.ts:6
     2  node_modules/rc-mentions/lib/Mentions.d.ts:44
     1  node_modules/rc-menu/lib/interface.d.ts:77
     1  node_modules/rc-notification/lib/interface.d.ts:19
     7  node_modules/rc-picker/lib/interface.d.ts:205
     1  node_modules/rc-picker/lib/PickerPanel/index.d.ts:40
     2  node_modules/rc-rate/lib/Rate.d.ts:23
     1  node_modules/rc-select/lib/BaseSelect.d.ts:19
     1  node_modules/rc-table/lib/interface.d.ts:183
     1  node_modules/rc-tooltip/lib/Tooltip.d.ts:31
     4  node_modules/rc-upload/lib/interface.d.ts:23
     1  node_modules/scroll-into-view-if-needed/dist/index.d.ts:76
    ```

Additional context

No response

@hand-dot
Copy link
Collaborator

hand-dot commented Apr 29, 2024

Hey @slim-hmidi

Can you try the bellow?

import { generate } from '@pdfme/generator';
import type { Template } from '@pdfme/common'; // <- change this line
import {writeFile} from 'fs/promises';
import path from 'path';
const generateInquiryPdf = async (template: Template, inputs: Record<string, string>[]) => {
    const generatedPdf = await generate({ template, inputs })
    await writeFile(path.join(__dirname, `inquiry.pdf`), generatedPdf);
}

@hand-dot
Copy link
Collaborator

ref: #474

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants