polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 354 forks source link

Typegen fails on 8.0.1 #4737

Closed nathanwhit closed 2 years ago

nathanwhit commented 2 years ago

After updating a project to the latest api version I ran into trouble trying to generate typescript types. Running

ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package mypackage/interfaces --input ./src/interfaces --endpoint ./mymetadata.json

now fails with Error: Cannot find module '../src/fromDefs.ts'.

I dug into the error a bit and found that we're hitting this catch statement with the error:

Error: ENOENT: no such file or directory, open 'mypackage/node_modules/@polkadot/typegen/cjs/templates/header.hbs'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at readTemplate (mypackage/node_modules/@polkadot/typegen/cjs/util/file.js:35:22)
    at Object.<anonymous> (mypackage/node_modules/@polkadot/typegen/cjs/util/formatting.js:81:62)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)

(where mypackage is the path to my project, just replaced for privacy)

jacogr commented 2 years ago

Umpf. Yes, it seems broken with the hbs paths, completely wrong. Will need a patch release.

jacogr commented 2 years ago

Fix here https://github.com/polkadot-js/api/pull/4738/files#diff-1e1848f1e213ca5973e744d62dc27b7804b8c879f44ddee82b25d7a9d2613305R26 - will be released as 8.0.2 from CI when merged.

polkadot-js-bot commented 2 years ago

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.