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

fix(libConfig): import default in CJS build #35

Merged
merged 1 commit into from
Oct 6, 2023
Merged

Conversation

ShGKme
Copy link
Contributor

@ShGKme ShGKme commented Oct 6, 2023

How to test

  1. Use chore: Bump @nextcloud/vue + @nextcloud/dialogs + @nextcloud/calendar-availability-vue nextcloud/server#40692 with the latest @nextcloud/vue
  2. Run npm test (or better just npx jest CalDavSetting for a single test)
  3. See [Vue warn]: Failed to mount component: template or render function not defined

A problem

By default,

Rollup assumes that the required value should be treated as the default export of the imported module, just like when importing CommonJS from an ES module context in NodeJS. This is different from the default behavior in many tools like Babel or TS.

As a result, when a CJS lib built with this config is used with such tooling, external dependencies are imported as an object with a default property.

// Inside NcComponent.cjs
const icon = require('vue-material-design-icons/Icon.vue)

// Imports as

{
  default: {
    name: 'Icon',
    render: () => {},
  }
}

// Instead of

{
  name: 'Icon',
  render: () => {},
}

Proposal

interop: auto adds a hack with __esModule to help tools interpret it.

Alternative

Formally __esModule is a hack. Supported by all the tolling but still.

interop: compat also works checking how the module was imported

See: https://rollupjs.org/configuration-options/#output-interop

P.S.

I'm not sure it fixes all the issues with the new CJS built. Checking...

@ShGKme ShGKme added bug Something isn't working 3. to review Ready to review labels Oct 6, 2023
@ShGKme ShGKme requested a review from susnux October 6, 2023 12:26
@ShGKme ShGKme self-assigned this Oct 6, 2023
@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Merging #35 (b108a87) into main (28a71a8) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
+ Coverage   80.22%   80.26%   +0.03%     
==========================================
  Files           8        8              
  Lines         536      537       +1     
  Branches       32       32              
==========================================
+ Hits          430      431       +1     
  Misses         74       74              
  Partials       32       32              
Files Coverage Δ
lib/libConfig.ts 88.81% <100.00%> (+0.07%) ⬆️

@susnux susnux merged commit 6ed5a46 into main Oct 6, 2023
11 checks passed
@susnux susnux deleted the fix/cjs-esm-interop branch October 6, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Ready to review bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants