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

Add module.exports to the main module #13

Closed
FlyingDR opened this issue Jan 20, 2023 · 7 comments
Closed

Add module.exports to the main module #13

FlyingDR opened this issue Jan 20, 2023 · 7 comments

Comments

@FlyingDR
Copy link

At this moment main module of the project does not include module.exports statement.

Of course it is not needed in this case, there is a practical reason: Vite reports a warning for modules without module.exports statements, effectively polluting logs with: suppress-experimental-warnings doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

Hope that it is not a big deal to update module in this way.

@dword-design
Copy link
Owner

@FlyingDR How do you use the package with vite? Can you give an example?

@FlyingDR
Copy link
Author

Sure, I use SvelteKit which, in its turn, uses Vite as a bundler and dev server.

I use Node.js 16 which reports JSON module import as an experimental feature. To remove this warning from Node.js I've added your package to the project and it causes Vite to report a warning, given above.

@dword-design
Copy link
Owner

Ok but how did you add the package to the project? Is it part of the Svelte config and if so, how does it look like?

@FlyingDR
Copy link
Author

No, I use it in a way, which is recommended by you, for console commands runner:

#!/usr/bin/env bash

if [ $# -eq 0 ]; then
  node --require=suppress-experimental-warnings console/index.js --help
else
  node --require=suppress-experimental-warnings console/index.js "$@"
fi

But it looks like Vite parses contents of the package.json and displays a warning even if your package does not involved into SvelteKit run anyhow.

@dword-design
Copy link
Owner

dword-design commented Jan 21, 2023

@FlyingDR Ok I dug myself into it and imho this is a vite issue. So, here is the regex that basically checks if this is a commonjs module and this looks pretty hacky to me. If the package would have require call or Object.assign or something similar, the warning would not be thrown anymore. I'd suggest to open an issue in the vite repo to fix it there.

The issue seems to also seems to happen with a lot of other packages:

@FlyingDR
Copy link
Author

@dword-design Thank you for such great research!

I've seen several similar issues in the Vite repository too, but it looks like that Vite' developers position is that external packages need to be fixed, not their code. But it may be worth opening another issue in Vite.

It is really strange that they're detecting CJS module by Object.assign() which has nothing to do with CJS...

If you prefer to keep your project as it is now - please close the issue.

@dword-design
Copy link
Owner

I'd say close for now and observe what Vite devs are doing.

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

No branches or pull requests

2 participants