-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Confusing error message when using import
inside CJS file
#56518
Labels
esm
Issues and PRs related to the ECMAScript Modules implementation.
Comments
marco-ippolito
added
the
esm
Issues and PRs related to the ECMAScript Modules implementation.
label
Jan 8, 2025
wongprom
added a commit
to wongprom/node
that referenced
this issue
Jan 15, 2025
- Added new tests for invalid imports in .cjs files. - Added tests for loading .mjs files in CommonJS packages. - Refactored assertions to align with project lint rules. - Verified all tests pass with Node.js tools and addressed related errors. - Formatted src/node_contextify.cc using clang-format for consistent code style. Refs: nodejs#56518
wongprom
added a commit
to wongprom/node
that referenced
this issue
Jan 15, 2025
- Updated `GetWarningMessage` in `node_contextify.cc` to handle `.cjs` files and emit appropriate warnings. - Normalized the warning message in tests to simplify comparison and improve readability. - Added specific tests to verify warnings for invalid imports in `.cjs` files and handling of `.mjs` in CommonJS packages. Note: The test currently compares the exact string value for warnings. This could be optimized by validating only the critical parts of the warning message. Refs: nodejs#56518
wongprom
added a commit
to wongprom/node
that referenced
this issue
Jan 15, 2025
- Added new tests for invalid imports in .cjs files. - Added tests for loading .mjs files in CommonJS packages. - Refactored assertions to align with project lint rules. - Verified all tests pass with Node.js tools and addressed related errors. - Formatted src/node_contextify.cc using clang-format for consistent code style. Refs: nodejs#56518
wongprom
added a commit
to wongprom/node
that referenced
this issue
Jan 15, 2025
- Updated `GetWarningMessage` in `node_contextify.cc` to handle `.cjs` files and emit appropriate warnings. - Normalized the warning message in tests to simplify comparison and improve readability. - Added specific tests to verify warnings for invalid imports in `.cjs` files and handling of `.mjs` in CommonJS packages. Note: The test currently compares the exact string value for warnings. This could be optimized by validating only the critical parts of the warning message. Refs: nodejs#56518
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version
23.6.0
Platform
Subsystem
esm
What steps will reproduce the bug?
file.cjs
file containingimport "path";
node file.cjs
How often does it reproduce? Is there a required condition?
/
What is the expected behavior? Why is that the expected behavior?
It should tell me that to use
import
inside file I need to use.mjs
and not.cjs
What do you see instead?
It also offers the solution of setting "type": "module" in the package.json, but that is wrong since my file is .cjs.
Additional information
No response
The text was updated successfully, but these errors were encountered: