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

No "exports" main defined error with Vitest #59

Closed
cexbrayat opened this issue Nov 22, 2022 · 0 comments · Fixed by #63
Closed

No "exports" main defined error with Vitest #59

cexbrayat opened this issue Nov 22, 2022 · 0 comments · Fixed by #63

Comments

@cexbrayat
Copy link

Running vitest in a project that uses chart.js v4 and chartjs-adapter-date-fns v2.0.1 results in:

Error: No "exports" main defined in [redacted]/node_modules/chart.js/package.json
 ❯ node_modules/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.js:8:72
      6|  */
      7| (function (global, factory) {
      8| typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('chart.js'), require('date-fns')) :
       |                                                                        ^
      9| typeof define === 'function' && define.amd ? define(['chart.js', 'date-fns'], factory) :
     10| (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Chart, global.dateFns));

This is similar to this other comment

Here is a repro using stackblitz: https://stackblitz.com/edit/vitest-dev-vitest-7iyfoz?file=test/basic.test.ts

The test just imports chartjs-adapter-date-fns.

A potential fix is to add the exports field to the adapter package.json:

 "exports": {
    ".": {
      "import": "./dist/chartjs-adapter-date-fns.esm.js",
      "require": "./dist/chartjs-adapter-date-fns.js"
    }
  }
@cexbrayat cexbrayat changed the title No "exports" main defined No "exports" main defined error with Vitest Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant