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

Consider publishing dual format with CommonJS compatibility #325

Closed
4 tasks done
otakustay opened this issue Dec 27, 2021 · 2 comments · Fixed by #1411
Closed
4 tasks done

Consider publishing dual format with CommonJS compatibility #325

otakustay opened this issue Dec 27, 2021 · 2 comments · Fixed by #1411

Comments

@otakustay
Copy link

Clear and concise description of the problem

We are moving to "moduleResolution": "nodenext" with TypeScript 4.6 nightly build, but for some ecosystem reasons we are unable to introduce "type": "module" to our packages.

Although vite as a CLI runs without any problem, the import {expect} from 'vitest' statement can be errored from TypeScript in IDE:

Module 'vitest' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.ts(1471)

This has no actual negative effects to us since we don't transpile .test.ts, but a red error is always there whenever we open our tests files.

image

Suggested solution

Consider publish both CJS and ESM formats and having exports field in package.json also references to CJS files.

Alternative

No response

Additional context

No response

Validations

@aleclarson
Copy link
Contributor

I think Vitest could simply publish a stub CJS module to appease TypeScript here?

When Vitest runs the test file, it will be compiled with the module entry point of Vitest, so it shouldn't cause any problems.

@aleclarson
Copy link
Contributor

aleclarson commented Jun 1, 2022

Scratch that. Looks like the issue is "type": "module" in Vitest's package.json

I can confirm that removing the type: module line fixes the TypeScript error. Can we publish Vitest without it, or would that cause problems?

edit: Ah, removing type: module means we'll have to publish the dist files with .mjs extension.

aleclarson added a commit to aleclarson/vitest that referenced this issue Jun 1, 2022
aleclarson added a commit to aleclarson/vitest that referenced this issue Jun 1, 2022
antfu added a commit that referenced this issue Jun 5, 2022
Closes #325

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants