-
Notifications
You must be signed in to change notification settings - Fork 44
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
Error when importing CommonJS module #156
Comments
sonnyp
added a commit
that referenced
this issue
Dec 12, 2024
Merged
sonnyp
added a commit
that referenced
this issue
Dec 12, 2024
Thanks for the details Could you check this fixes it for you ? #157 |
sonnyp
added a commit
that referenced
this issue
Dec 12, 2024
v3.1.0 is out and fixes the problem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there!
When working with node-opcua-xml2json which uses ltx, I encounter the following error:
Because node-opcua-xml2json is compiled into CommonJS, it uses the compiled CommonJS version of the ltx parser.
But node thinks that it is an ESM module, because the package.json in the root of the project specifies
"type": "module"
.In my testing I found that changing
"type": "module"
to"type": "commonjs"
fixes this issue.I saw that the lib folder has another package.json file which has it's type set to "commonjs", but node20 does not seem to pick it up when working with node-opcua-xml2json.
I think changing the package.json in the root folder would be ideal, because it would still work the way it does right now.
In addition according to this source specifying the main ESM entry point using "module" is not standard in node, and only "main" is officially supported. And since "main" is set to
lib/ltx.js
and type is set to module, it thinks that the compiled js is actually ESM instead of CommonJS.One more thing that would make it super clear to node where each type of files are, would be to use package exports, more specifically conditional exports.
The text was updated successfully, but these errors were encountered: