Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'i18n') at setLanguage.js:44:12

Which product are you using?
PDF.js Express Viewer

PDF.js Express Version

UI version ‘8.7.0’
Core version ‘8.7.0’
webviewer.min.js ‘8.7.0’
Build ‘Ny8yMC8yMDIyfDJhMWM5ZWYwOA==’

Detailed description of issue
Error when setting language
“setLanguage.js:44 Uncaught (in promise) TypeError: Cannot set properties of undefined (setting ‘i18n’) at setLanguage.js:44:12”

Expected behaviour
Set the language without generating an error.

Does your issue happen with every document, or just one?
Happens with every document, and multiple instances.

Link to document
(Transfer - Dropbox)

Code snippet

  ngOnInit() {
    this.route.paramMap.subscribe((paramMap: any) => {
      if (paramMap.get('bookmark') !== null) {
        this.bookmarkName = paramMap.get('bookmark').replace(/%20/g, ' ');
      }
    });

    this.setLanguageDocument();
  }

  ngAfterViewInit(): void {
    WebViewer(
      {
        path: '../lib',
        // initialDoc: '/assets/documents/help/' + this.languageDocument,
        initialDoc: '/assets/documents/help/lorem-ipsum.pdf',
        licenseKey: 'VMeLR5MsW5lX3X9YfqQF',
        css: '/assets/pdf-viewer/pdf-viewer.css',
      },
      this.viewer.nativeElement
    ).then((instance: any) => {
      const { Core, UI } = instance;

      UI.setHeaderItems((header: any) => {
        header.getHeader('default').push({
          img: 'icon-header-print-line',
          index: -1,
          type: 'actionButton',
          element: 'printButton',
          onClick: () => {
            instance.UI.print();
          },
        });
        const items = header.getItems().filter((item: any) => item.type !== 'divider');
        header.update(items);
      });

      instance.setFitMode(instance.FitMode.FitWidth);

      Core.documentViewer.addEventListener('documentLoaded', () => {
        Core.documentViewer
          .getDocument()
          .getBookmarks()
          .then((bookmarks: any) => {
            if (this.bookmarkName !== '') {
              this.bookmarks = bookmarks;
              this.currentBookmark = this.bookmarks.find(
                (bookmark: any) => bookmark.name.toLowerCase() === this.bookmarkName.toLocaleLowerCase()
              );

              if (this.currentBookmark) {
                Core.documentViewer.displayBookmark(this.currentBookmark);
              }
            }
          });

        UI.setActiveLeftPanel('outlinesPanel');
        UI.openElements(['leftPanel']);

        console.log(UI);
        UI.setLanguage(this.localizationService.currentLaungageCode);

        UI.disableElements([
          'menuButton',
          'leftPanelButton',
          'zoomOverlayButton',
          'viewControlsButton',
          'selectToolButton',
          'panToolButton',
          'thumbnailsPanelButton',
        ]);
      });

      UI.useEmbeddedPrint(true);
    });
  }

  onBack() {
    this.location.back();
  }

  setLanguageDocument() {
    switch (this.localizationService.currentLaungageCode) {
      case 'en':
        this.languageDocument = 'Host Help.pdf';
        break;
      case 'fr':
        this.languageDocument = 'Host Help (fr).pdf';
        break;
      case 'es':
        this.languageDocument = 'Host Help (es).pdf';
        break;
      case 'de':
        this.languageDocument = 'Host Help (de).pdf';
        break;
      case 'it':
        this.languageDocument = 'Host Help (it).pdf';
        break;
      case 'pt':
        this.languageDocument = 'Host Help (pt).pdf';
        break;
      default:
        this.languageDocument = 'Host Help.pdf';
    }
  }

This was not an issue prior to the holidays, but now it is. Seems to be a new issue. I was reading another post in the forum and they said they were having issues because of upgrading node. I realize I upgraded Node over the break as well. I’ll do some testing to see if that’s the issue for me as well.

Hi @alexb

An other issue was solved by downgrading node to v14. What version are you experiencing this error on?

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.

Hi @zserviss,

Thanks for your quick reply.

Prior to the break I was using Node 16.15.0, and I wasn’t having any issues, then over the break I upgraded to the latest LTS 18.12.1. I just tested with 14.20.0, and 16.15.0 and it hasn’t resolved the issue unfortunately. So I don’t think it’s Node version in my case.

Which language code is this error appearing on exactly?

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.

The default is ‘en’, but it’s the same for every language code I’ve tested

image

Does is still error out when passing in a hard coded string?

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.

Yes, even when I pass in:

UI.setLanguage('en');
1 Like

In the console can you manually change the language?

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.

@zserviss Is this what you meant?

@zserviss It looks like it’s an error in the setDatePickerLocale

1 Like

Sorry for not being clearer, what I mean is to invoke the call through the console on the WebViewer instance.

Just be sure to choose webviewer from the drop down on the DOM elements.

image

I’m unable to reproduce this on the demo site but I’ll dig more into why i18n is undefined.

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.

@zserviss It looks like the result is the same when I follow your steps

Since you said that this is occurring after updating node, could you reinstall/update i18n to see if that has any effect?

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.

I delete my node_modules, package-lock.json, updated i18n, and reinstalled all my packages. The issue did not resolve.

Hi @alexb

Since I am unable to reproduce this issue, can you send a sample project?

Also maybe try a fresh install of express to see if that has an effect.

Best Regards,
Zach Serviss
Web Development Support Engineer
PDFTron Systems, Inc.

@zserviss Sorry I’ve been with other things. I’ll make time this week to put together a sample project.

1 Like

@zserviss I’m working with @alexb, here is a sample project where you can see the error after the PDF document loads.

Thanks!

Hi @mike1,

Thanks for the sample project. Looks like I’m able to reproduce with this.

I’ll add this to our backlog to be worked on and let you know the fix in this thread.

Best Regards,
Zach Serviss
Platform Support Engineer
PDFTron Systems, Inc.

Sounds great, thanks for your help!