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

Vitest error: PostHog seems to be an ES Module but shipped in a CommonJS package #1450

Open
MathiasWP opened this issue Oct 3, 2024 · 1 comment
Labels
SDK Support General SDK issues rather than being related to a feature team

Comments

@MathiasWP
Copy link

They explicitly asked me to make an issue asking you to ship the file in .mjs extension or add "type": "module" in their package.json, so here it is.

image
@JayaKrishnaNamburu
Copy link

This can be parsed in three different ways.

1

Marking the whole package as es-module. Which means, adding type: module inside the package.json file. Which effectively lets bundlers know they are using a es module.

2

Adding .mjs extension to the files, so when loaded they are handled as es-modules.

3

This is one of the most used ones, that is to add exports field to the packages. jspm.io does it automatically to all the packages. It takes into consideration of the main and then the files keys in the package.json.
You can see the exports field that is pre-populated
https://ga.jspm.io/npm:[email protected]/package.json

"exports": {
    ".": {
      "module": "./dist/module.js",
      "default": "./dist/main.js"
    },
    "./react": {
      "module": "./react/dist/esm/index.js",
      "default": "./react/dist/umd/index.js"
    },
    "./react/dist/esm/index.js": "./react/dist/esm/index.js",
    "./dist/main.js": "./dist/main.js",
    "./dist/module.js": "./dist/module.js",
    "./react/dist/umd/index.js": "./react/dist/umd/index.js",
    "./dist/main.js!cjs": "./dist/main.js",
    "./react/dist/umd/index.js!cjs": "./react/dist/umd/index.js"
  }

But doing this on your own in the package.json will be the best possible way. I looked into it, i just have some doubts. The package exposes main and module. Happy to help in creating one 👍

@robbie-c robbie-c added the SDK Support General SDK issues rather than being related to a feature team label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK Support General SDK issues rather than being related to a feature team
Projects
None yet
Development

No branches or pull requests

3 participants