-
Notifications
You must be signed in to change notification settings - Fork 14
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
Universal Bundle #66
Universal Bundle #66
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think CommonJS is kind of old school. I expect you just need to make your other project type: module
in order to get things to work.
I tried that... it was a no go with the other conflicting configuration issue... I would love to see a better alternative, but for now at least this removes the conflict. Or rather, until the other project has some non-conflicting configuration (safe imports with these imports) at least this adjustment removes the conflict. |
I looked at how some other projects do it, and some include both ES and CommonJS The aforementioned link explicitly provides a way to support both files for use with // package.json
{
"exports": {
"import": "./index-module.js",
"require": "./index-require.cjs"
},
"type": "module"
} This probably requires two TS build steps, but that shouldn't be a big deal (and don't forget you can "inherit" ts config files for each module system you want to support). Edit: there is a section on dual CommonJS/ES module packages: https://nodejs.org/api/packages.html#dual-commonjses-module-packages |
That's great news I'll have to look into it. However I don't believe there is any reason why this project or anyone wants to support JS "require" imports if that's what all this is about. These conflicting imports have only ever come up in typescript projects. Note that I don't know what the changes proposed here actually mean but I am beginning to interpret it as "CommonJS" is somehow related to the import syntax convention. Up until now I was thinking these changes would make the package more universally compatible - but it doesn't need to be compatible with old JavaScript by any means. |
So the issue is that your TypeScript setup is generating JavaScript code with
You are basically changing this project to use the "old school" way of requiring module dependencies instead of ES modules. The above link describes how you can support both, so it would be providing more compatibility. |
This problem is still very prevalent causing issues with transformation of near-safe into an npm package: In fact, there are no issues with this for build it only becomes a problem when trying to run the script file. |
Ok - Finally got something compatible thanks to the help of @jfschwarz and his amazing suggestion to use https://github.com/privatenumber/tsx! |
Some projects have been struggling to import from this package because of some node target stuff I do not understand.
Example project: BitteProtocol/near-safe#1
I have tried to repackage the project and locally tested with
npm link
. Will publish a beta release from this branch and proceed.cc @nlordell
Note that somehow also this change wound up formatting from previously unformulated files.