-
Notifications
You must be signed in to change notification settings - Fork 366
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
[ERR_UNSUPPORTED_DIR_IMPORT] ES Module factory exports #819
Comments
The relevant source code should be here. Also linking this: CONTRIBUTING (if not already seen). |
Fantastic. I will read the Contributing guide and see if I can propose a patch. Seems simple enough. |
I am seeing this as well. While versions 8.2.0 of EDIT: never mind, I found it. Hope the change I proposed in the PR is valid. |
I recently came back to this and saw the news about 8.2.0. Thanks so much for adding your PR as well to fully make Typechain work with ESM! |
I tried it using local linking and it worked! I also published the branch on npm if people want to test it out (though I'd recommend using the official package once it is released or even better using local linking). This was a blocker for my team and it is easier for us to use npm than do local linking. |
Note to get this working is not as simple as changing your package.json due to dependencies using the official package names. Instead you will have to use aliasing (https://pnpm.io/aliases). So unless you absolutely need npm package support I would not recommend this and instead use local linking for development (clone @chmanie branch, build, and link https://pnpm.io/cli/link). Or just be patient and wait for the team to hopefully accept the PR and release a new version! Here are a few steps if you need npm support:
module.exports = {
hooks: {
readPackage(pkg, context) {
//Global version overrides
const depsOverrides = {
"typechain": "npm:@owlprotocol/typechain@8.2.0",
};
Object.entries(depsOverrides).map(([name, version]) => {
if (pkg.dependencies[name]) pkg.dependencies[name] = version;
if (pkg.devDependencies[name]) pkg.devDependencies[name] = version;
if (pkg.peerDependencies[name]) pkg.peerDependencies[name] = version;
})
},
afterAllResolved(lockfile) {
return lockfile;
}
}
} |
Hey there @leovigna, I'm not sure I understand why E.g.
|
I guess it depends what bundler you use. I use esbuild and since my final output is js files the type imports just get removed anyways. It is preferable to still have the file extensions for type exports too probably but has no direct impact on ECMAScript since at the end of the day since you are just running js. |
Hm, I see. I'll try to add a pull request that does that. I'm personally using |
I'm still seeing this issue of missing file extensions. Can someone confirm that @chmanie's fix is included in the current latest published versions? I'm using typechain 8.3.2 and typechain/ethers-v5 11.1.2. Is there a setting I need to enable other than the Edit: I've found the problem and submitted a PR to fix here: #898 |
Note: I am uncertain if this is an issue with
typechain
or@typechain/ethers-v5
. This issue might also exist with@typechain/web3-v1
Recently upgraded typechain in my project to the versions below and I appreciate the modularized exports as we are looking to export typechain types in our contract's npm package. However there is a slight issue when using ESModules due to incorrect exports that do not explicit use the file extensions.
Used versions:
Below a short example snippet of the typechain generated
index.ts
when using openzeppelin.We then export these types in our package so developers can easily use them.
There is a slight issue when using ESModules. When using ESModules, js files MUST be imported with explicit file name extensions. However this only applies to importing variables and NOT types in TS files (as these have no runtime value). Therefore in the snippet above, while the contract types are properly exported, the factory exports (both
factories
andIERC1155Upgradeable__factory
) don't just export types but rather a class that mimics ethers factory but with proper types. Therefore the import breaks because the factory is not exported with explicit reference to the.js
file. Here would be an example fix to the above snippet.Please let me know if you have an idea where the logic for the export file generation is and I would be open to looking into making the patch.
The text was updated successfully, but these errors were encountered: