Skip to content

instanceof breaks in dev mode #9528

@bryanmylee

Description

@bryanmylee

Describe the bug

I am building a table library for Svelte which uses classes and instanceof checks quite extensively. I've noticed that the behaviour of instanceof is different between yarn dev and yarn build && yarn preview. More specifically, instanceof returns false in cases where I expect it to return true.

My core library (svelte-headless-table) exposes an argument that accepts an object of plugins. These plugins are exported from svelte-headless-table/plugins that can extend the library's functionality. Some plugins use instanceof checks for their logic, but instanceof results in incorrect behaviour.

The issue persists with npm and pnpm.

Catching the issue

The issue does not surface if I use npm link or pnpm.overrides to debug the package. I've only been able to catch the issue by adding console.log statements to the packaged library files in node_modules/. I've added instructions to the reproduction repo on how to do so.

Dev mode

dev mode instanceof check

Preview mode

preview mode instanceof check

Relevant discussion

An existing issue thread exists here.

Reproduction

https://github.com/bryanmylee/svelte-headless-table-vite-instanceof-check

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 111.06 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.15.0/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
    Watchman: 2022.07.04.00 - /Users/bryanmylee/homebrew/bin/watchman
  Browsers:
    Chrome: 103.0.5060.134
    Safari: 15.5

Used Package Manager

yarn

Logs

No errors are thrown and the library fails silently in dev.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions