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

Switch to .cjs for package.json main #196

Closed
ViktorQvarfordt opened this issue Sep 15, 2021 · 3 comments
Closed

Switch to .cjs for package.json main #196

ViktorQvarfordt opened this issue Sep 15, 2021 · 3 comments

Comments

@ViktorQvarfordt
Copy link
Collaborator

The problem I am facing
Yarn pnp is not compatible with ESM.

The solution I would like
Change package.json files like so:

-  "main": "dist/hocuspocus-server.esm.js",
+  "main": "dist/hocuspocus-server.cjs",

Additional context
I couldn't open a PR (cannot push a branch or fork the repo). But I attach a diff for convenience. diff.txt

@hanspagel
Copy link
Contributor

Thanks! We decided to go with ECMAScript modules only. Read more about the reasoning here:
https://blog.sindresorhus.com/hello-modules-d1010b4e777b

Also, the linked comment has interesting insights, too:
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#gistcomment-3850849

We know that this can causes issues in some setups (older Node versions, or Yarn pnp), but want to build a new package on a modern foundation. Maybe you can work around this in some way, for example with a separate project setup.

@ViktorQvarfordt
Copy link
Collaborator Author

I see, that make sense. I found how to patch the package using yarn patch. With that we can still keep the code in our yarn workspaces setup. Closing this issue but leaving some additional notes here for future reference if someone else searches for this and finds this issue:

yarn add @hocuspocus/server
yarn patch @hocuspocus/server
# edit relevant files (see output of yarn patch above) as described in the first post
yarn patch-commit /private/var/folders/[generated-path] > hocuspocus-server.patch
# update package.json dependency in your yarn package to look something like this:
#  "@hocuspocus/server": "patch:@hocuspocus/server@^1.0.0-alpha.69#./hocuspocus-server.patch",

@hanspagel
Copy link
Contributor

Oh, that’s a great solution. Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants