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

this is transpiled incorrectly in a class instance field #7676

Closed
7 tasks done
arackaf opened this issue Apr 11, 2022 · 2 comments
Closed
7 tasks done

this is transpiled incorrectly in a class instance field #7676

arackaf opened this issue Apr 11, 2022 · 2 comments
Labels
bug: upstream Bug in a dependency of Vite feat: commonjs @rollup/plugin-commonjs issue inconsistency Inconsistency between dev & build

Comments

@arackaf
Copy link

arackaf commented Apr 11, 2022

Describe the bug

I have a library, which is transpiled (by Vite) to something like this

'use strict';

Object.defineProperties(exports, {
  __esModule: { value: true },
  [Symbol.toStringTag]: { value: 'Module' },
});

class MutationManager {
  runMutation = (variables) => {
    console.log('RUN MUTATION');
  };
  currentState = {
    runMutation: this.runMutation,
  };
}

exports.MutationManager = MutationManager;

Note the currentState property.

When this library is loaded into a Vite app, and built (ie npm run build), currentState is transformed incorrectly, where runMutation: this.runMutation becomes

__publicField(this, "currentState", {
  runMutation: commonjsGlobal.runMutation
});

The Vite.new link below reproduces this all in full (after running npm run build)

Reproduction

https://stackblitz.com/edit/vitejs-vite-f18nb2?file=vite.config.js&terminal=dev

System Info

Repro is the same on my machine vs the sandbox link above, but for whatever it's worth, mine is

System:
    OS: macOS 12.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 442.83 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.11.1 - /usr/local/Cellar/nvm/0.38.0/versions/node/v16.11.1/bin/node
    Yarn: 1.22.17 - /usr/local/Cellar/nvm/0.38.0/versions/node/v16.11.1/bin/yarn
    npm: 8.0.0 - /usr/local/Cellar/nvm/0.38.0/versions/node/v16.11.1/bin/npm
  Browsers:
    Chrome: 100.0.4896.75

Used Package Manager

npm

Logs

n/a

Validations

arackaf added a commit to arackaf/micro-graphql-react that referenced this issue Apr 11, 2022
@bluwy
Copy link
Member

bluwy commented Apr 11, 2022

Looks like an upstream issue in @rollup/plugin-commonjs: rollup/plugins#922

@bluwy
Copy link
Member

bluwy commented Oct 29, 2023

Fixed in rollup/plugins#1537

@bluwy bluwy closed this as completed Oct 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite feat: commonjs @rollup/plugin-commonjs issue inconsistency Inconsistency between dev & build
Projects
None yet
Development

No branches or pull requests

3 participants