-
Notifications
You must be signed in to change notification settings - Fork 45
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
fix type imports for nodejs esm #408
Conversation
i should probably mention, i'm importing like: |
Hey @rosmcmahon , why do you import like this? |
if i try
|
I see, we will need to fix it then. In the meantime, can you please also verify version |
So I've prepared an example from a template (https://github.com/chriswells0/node-typescript-template) and it works fine: Repo with example script is here: https://github.com/warp-contracts/ts-node-test/blob/master/src/index.ts |
the above appears to be a cjs test?
|
this is my test tsconfig.json: {
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node v18 LTS ESM",
"compilerOptions": {
/* Modules */
"lib": ["ES2022","DOM"],
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "bundler",// "NodeNext",
"outDir": "./build",
/* Type Checking */
"strict": true,
"strictNullChecks": true, //ts_belt
"noUncheckedIndexedAccess": true, //ts_belt
// "typeRoots": ["./node_modules/@types", "./node_modules/warp-contracts/lib/types/index.d.ts"],
/* Interop Constraints */
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
// "resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
/* Completeness */
"skipLibCheck": true,
"checkJs": true
}
,
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
} |
incidentally, if i try specifying the typeRoots like commented out above, i get:
|
Yes, this is also how tsc is configure in our SDK https://github.com/warp-contracts/warp/blob/main/tsconfig.json#L6 Re. your config - what is The allowed values are: |
ESM version warp-contracts/ts-node-test@effaa73 |
arweave-js is purely a commonjs library. your app can be esm or cjs and import it though. if your test app is set to
this is a new option since Typescript@5. once i updated to v5 i had import problems when using "NodeNext" for esm. |
"./mjs": "./lib/mjs/index.js", | ||
".": "./lib/cjs/index.js" | ||
".": { | ||
"require": "./lib/cjs/index.js", |
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.
@asiaziola what do you think? I believe we've been here before and it was causing some fuckups for some of the web bundlers?
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.
we can quickly test it i guess, can you release a beta version with the change so I can run tests on bundlers?
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.
also - shouldn't we attach types to both of the versions?
so it will look sth like:
"require": {
"types": "./not-sure-whats-the-path-to-types",
"default": "./lib/cjs/index.js"
}
warp-sdk is by default compiled to cjs format. But there is an mjs version - for the sake of using it from .mjs files. This version is not compiled from scratch - only a ESM wrapper is being created. This is also the reason why there is a separate package.json for the mjs version (with the 'type' set to 'module'). This is how official node.js docs suggest to do this (i.e. create a wrapper and not compile separately to cjs and esm - for reference https://nodejs.org/api/packages.html#dual-package-hazard). As I've mentioned - this commit warp-contracts/ts-node-test@effaa73 works for me - is it not a viable solution for you? Sorry for making such a big problem from such a small change, but our expierience is that such changes always break sth for someone else (usually for some web bundlers, like rollup, esbuild, next.js/vite-whatever-they-are-using-underneath, etc.) |
no absolutely, these tiny changes are key.
yeah, i'm interested in this hybrid packaging. i'm not a fan of this "rip the band aid off" approach of going full esm, and giving the finger to the rest of the js/ts ecosystem 😅 |
somehow skipped over this, let me check, thanks! |
hmm, if change the moduleResolution in your test project we are back to the original error. feel free to close! |
We will play with it a bit more :-) |
I'll try with facebook/lexical#4160 (comment) - I guess we're not the only ones having issues with the new moduleResolution option... |
Though in this case it's probably more of a nolimits4web/swiper#6508 |
ok, so this one works with the new
|
https://github.com/warp-contracts/warp/pull/410/files |
Agree to closing. I'm not sure I should be setting moduleResolution like that after all. |
Sorry, we've tried with different settings, but each time at least one of our e2e test (for the concrete webbundler) was failing. |
FYI this library is now broken with |
i have definitely not tested this any further than for my own purposes.
environment:
error seen: