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

The object is created with the old class name, but the instanceof check is performed with the renamed class name #18036

Open
7 tasks done
duttabhishek6891 opened this issue Sep 5, 2024 · 2 comments

Comments

@duttabhishek6891
Copy link

duttabhishek6891 commented Sep 5, 2024

Describe the bug

We have a FlexGridPdfConverter class in our library (Wijmo). When we use the draw() method to draw the FlexGrid into a PdfDocument it produces an error in the constole: “Uncaught ** Assertion failed in Wijmo: Invalid argument: "value". Error”.
The error is caused because of failure of following check: “e instanceof PdfPen”
The reason is that the “e” variable contains the instance of “PdfPen” instead of “PdfPen2”.

You may observe the same in the images below:

image

image

Please note that I tried to run the exact code in an esbuild setup, and the issue does not occur. In esbuild setup also, the names are modifed by appending the suitable number in front of classes.

image

Reproduction

https://stackblitz.com/edit/vitejs-vite-msmvhy?file=index.html

Steps to reproduce

Steps to replicate the issue:

1 Extract the sample: instanceof check issue.zip
2. Run “npm i -f” and “npm run dev” to install the dependencies and run the sample.
3. Click on the “Export” button.
4. Observe the error in the console: “Uncaught ** Assertion failed in Wijmo: Invalid argument: "value". Error”
5. Click on the second link displayed in the error message.

image

  1. Place a breakpoint at the location and format the code.
  2. Refresh the page, open developer tools and click again on “Export” button.
  3. Format the code if required and press “F8” to pass the breakpoint this time.
  4. Observe that the next time the flow hit the breakpoint, “e” contains an instance of “PdfPen” instead of “PdfPen2”.

Verifying that the issue does not occur in simple esbuild setup:

  1. Extract the sample: esbuild-purejs.zip

  2. Run “npm i -f” to install the dependencies and open the sample either using “live server extension” or by running “npx http-server -o” command from terminal.

  3. Click on the “Export” button.

  4. Observe that the FlexGrid can be exported successfully.

System Info

Output of “npx envinfo --system --npmPackages '{vite,@vitejs/*,rollup}' --binaries –browsers”
  System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1270P
    Memory: 3.11 GB / 15.69 GB
  Binaries:
    Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.3.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.2283.0), Chromium (127.0.2651.105)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vite: ^5.4.1 => 5.4.3

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Sep 5, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Sep 15, 2024

From a quick look, it looks like deps optimization is confused with "self import" used by wijmo packages.

For example, @mescius/wijmo.pdf has this line https://unpkg.com/browse/@mescius/[email protected]/es5-esm.js

import*as selfModule from"@mescius/wijmo.pdf"

which is optimized (pre-bundled) to node_modules/.vite/deps/@mescius_wijmo__pdf.js like this (which references non-pre-bundled code and thus dual package issues):

import * as selfModule from "/node_modules/@mescius/wijmo.pdf/es5-esm.js?v=e22d289e";

The potential workaround is to exclude these packages from optimization since they are mostly bundled already. A following config makes your "export" button work in the reproduction:

https://stackblitz.com/edit/vitejs-vite-wzsyr5?file=vite.config.ts

import { defineConfig } from 'vite';

export default defineConfig({
  optimizeDeps: {
    exclude: [
      '@mescius/wijmo.pdf',
      '@mescius/wijmo.grid.pdf',
      '@mescius/wijmo.grid',
    ],
  },
});

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