-
Notifications
You must be signed in to change notification settings - Fork 358
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
Typegen Usage which worked with 9.14.2 doesn't work with 10.1.2 #5540
Comments
Ok, I found pages and pages of threads on google with regards to The quick fix seems to be (which mostly works for me on your reproduction) -
(In your specific example there is Doing that makes it generate everything. What is weird here is that you would expect, when running as ESM, you would not need (Swapping the ... Addendum: the above doesn't quite work, it still missing loading definitions & lookup. The |
Part of the trouble is that, if e.g. when there's some error related to lookup definitions, the generated
whereas it 'should' look more like:
And because of the missing Rather, in the example, the problem isn't so much generating the code, so much as (In my example, I can ignore I can kinda-sorta work around it by directly modifying the
to have |
|
10.1.3 patch release is out that fixes the (completely incorrect), |
With a
Logging
So I changed it back to It works for a bit, but then at the end throws this error:
Logging the error, a property says that |
Another new problem in 10.1.2 and 10.1.3 is that
In 10.1.2 and 10.1.3
This breaks the build, I am using the |
That should really not break the build at all. It work in both TS EDIT: I do get an endless stream of errors in the above repo if I remove the tsonfig.json I added with |
@montogeek On your |
What Node version are you using? |
|
Something is weird here with See the 2 commands and the outputs - > ts-node --esm --skipProject ./node_modules/@polkadot/typegen/scripts/polkadot-types-from-defs.mjs --package @efinity/api-augment/interfaces --input ./src/interfaces --endpoint ./metadata.json
ERROR: Unable to load user definitions: exports is not defined in ES module scope
<somewhere>/polkadot-js-typegen-efinity/src/interfaces/types.ts
Generating
Writing
<somewhere>/polkadot-js-typegen-efinity/src/interfaces/augment-types.ts
Generating
Writing
2023-03-15 14:42:58 REGISTRY: Unknown signed extensions CheckFuelTank found, treating them as no-effect
<somewhere>/polkadot-js-typegen-efinity/src/interfaces/lookup.ts
Generating
Writing And then via loader (no > node --loader ts-node/esm ./node_modules/@polkadot/typegen/scripts/polkadot-types-from-defs.mjs --package @efinity/api-augment/interfaces --input ./src/interfaces --endpoint ./metadata.json
(node:27028) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
<somewhere>/polkadot-js-typegen-efinity/src/interfaces/types.ts
Generating
Extracting interfaces for something
Writing
<somewhere>/polkadot-js-typegen-efinity/src/interfaces/augment-types.ts
Generating
Writing
2023-03-15 14:43:31 REGISTRY: Unknown signed extensions CheckFuelTank found, treating them as no-effect
<somewhere>/polkadot-js-typegen-efinity/src/interfaces/lookup.ts
Generating
Writing Have no clue what the difference would be between |
This output seems to indicate it's reading CommonJS code, when it's expecting to read an ESM module. And rgoulter/polkadot-js-typegen-efinity@6e193452fc180efdc8d275c341839e4bdd70c4d1HH is enough to be able to run the commands in the README, using I'd be happy for the issue to be closed; or maybe it can catch other problems people are having with changes since 9.14.2. |
EDIT: The below was fixed by adding the magic line: e.g.
I've moved our typegen project over to ESM and i've run into the same issue as reported here (with no workaround found yet).
https://github.com/PureStake/moonbeam/tree/typescript-api-2201/typescript-api
|
I'm not convinced that node --loader ts-node/esm node_modules/.bin/polkadot-types-from-defs --package @moonbeam/... did the trick above (for me). EDIT: ... or the EDIT in the comment preceding mine, |
@jacogr the reason the above probably works for you is that you must have set Or have it as an environment variable i.e. In any case, glad this is sorted! |
@jacogr By applying the option 1 described here, I am indeed able to generate definitions. However, chain types are not generated (
After a couple of hours debugging, I figured out that the process is actually killed because of the 1005 event code (see this line) and type generation is simply not executed. A workaround is to comment out the line. It does not solve the unexpected event code issue, but at least types are properly generated. |
Indeed. Looking at the above code link promise is actually not properly tracked/handled -
So basically that should be adjusted to only resolve/reject once (onmessage/onerror/onclose) aka when we have a response, we don't care if things go wrong with the connection so should not perform any exit inside there. Said differently whichever of there we find once should determine the Promise result... once. (It seems it was expecting all RPCs nodes to always behave and that assumption doesn't always hold) |
Am still getting errors in lookup.ts as it is not generated as ES module I think and cannot export the types to other modules hence breaking the code. |
In version 10.1.2, the export method has changed: in version 9.14.2: which disrupts the structure. I have tried all the mentioned methods above, but none of them successfully resolve the issue. |
I have created PR for docs on how we generate these types. I hope that it will be beneficial to someone. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query. |
I'm submitting a ...
What is the current behavior and expected behavior?
Code which worked with
@polkadot/api
v9.14.2
doesn't work withv10.1.2
. -- Likely same as #5524 (comment)Some clarification on what changes are needed would be useful.
Example code (& the commands used) can be found here: https://github.com/rgoulter/polkadot-js-typegen-efinity -- It's a pretty bare-bones usage of
typegen
, to generate the code, and includes a smallexample
TypeScript program which uses the generated types.The latest commit there updates the
@polkadot/typegen
to10.1.2
(and inexample/package.json
, its@polkadot/api
to10.1.2
).I'm having trouble figuring out what changes I need to make to get it to work with
10.1.2
.What goes wrong:
When it runs
polkadot-types-from-defs
, it has problems loading thedefinitions.ts
:When running
polkadot-types-from-chain
, some.ts
code is generated, but the generated code then leads to errors when trying to build it.Sample errors when trying to run
tsc
inexample
:Problems running with
ts-node-esm
, too:If instead of
ts-node
, I tryts-node-esm
,polkadot-types-from-defs
abruptly exits without an error message:If instead of
ts-node
, I tryts-node-esm
,polkadot-types-from-chain
is still unable to lookup the definitions:n/a
Linux.
The text was updated successfully, but these errors were encountered: