paritytech / capi

[WIP] A framework for crafting interactions with Substrate chains
https://docs.capi.dev
Apache License 2.0
104 stars 9 forks source link

Unable to use CAPI on stackblitz or codesandbox #1129

Open josepot opened 1 year ago

josepot commented 1 year ago

DEMO on a TS project

DEMO on a JS project

harrysolovay commented 1 year ago

Seems the specified Capi version in both of those is 0.0.1. Should be 0.1.0-gamma.1.

josepot commented 1 year ago

Seems the specified Capi version in both of those is 0.0.1. Should be 0.1.0-gamma.1.

Then perhaps the docs should be updated? Because npm i capi installs version 0.0.1

harrysolovay commented 1 year ago

Perhaps in stackblitz it does. Doesn't on my machine.

josepot commented 1 year ago

Also installing version 0.1.0-gamma.1 on stackblitz produces the following error:

A FAILURE: PACKAGE NOT FOUND
Unable to find package @capi/westend-dev in the NPM registry.
Please try installing a different package name
ryanleecode commented 1 year ago

Seems to be an issue with how they are runnning browser code... A node project is able to install capi

https://stackblitz.com/edit/stackblitz-starters-2u3qzv?file=index.js

josepot commented 1 year ago

Seems to be an issue with how they are runnning browser code... A node project is able to install capi

https://stackblitz.com/edit/stackblitz-starters-2u3qzv?file=index.js

to install it, yes. To run it: no 🙁. Try importing anything from CAPI and running it (it uses node 16, so...)

tjjfvi commented 1 year ago

Looks like their browser setup doesn't correctly handle URL packages (which we use for codegen), and their node setup uses an old version of node. I don't see much we can do here 🤷

We'll eventually build a Capi playground (#1153) which should address some of these usecases.

josepot commented 1 year ago

Looks like their browser setup doesn't correctly handle URL packages (which we use for codegen), and their node setup uses an old version of node. I don't see much we can do here 🤷

We'll eventually build a Capi playground (#1153) which should address some of these usecases.

Hi @tjjfvi,

I wanted to put forward a suggestion regarding the issue at hand. It would be beneficial to leave the issue open until a viable alternative or solution is identified. In my opinion, keeping it open would be advantageous because the ability to quickly demonstrate issues or features in the browser holds immense value. My concern is that a CAPI playground might not adequately address the needs of the majority of use cases. For example, it might not be suitable for demonstrating node project setups, parcel project setups, vitejs setups, and more.

With that in mind, I kindly request that you reconsider reopening this issue and collaborate on devising an action plan for bundling CAPI in a manner that truly serves the community's needs. While a CAPI playground is a nice addition, it is crucial to address this urgent matter as I previously explained. The CAPI playground falls short in meeting the requirements of the majority of use cases, and as far as I am aware, there hasn't been significant interest expressed by anyone other than CAPI team members.

Thank you for considering this suggestion, and I look forward to working together to find the best solution.

tjjfvi commented 1 year ago

I'm not sure there's anything we can do to fix this, but I'll still reopen it to track the status. (Perhaps stackblitz will soon update their version of Node and unblock this.)

josepot commented 1 year ago

I'm not sure there's anything we can do to fix this, but I'll still reopen it to track the status. (Perhaps stackblitz will soon update their version of Node and unblock this.)

Could you please also look into why it doesn't work on codesandbox? 🙏

Also, the issue with stackblitz goes beyond node, as it can not be used on regular TS/JS projects, either. So, IMO that can (and IMO should) be fixed as it has to do with the way that the library is being packaged.

ryanleecode commented 1 year ago

What is the error you are getting on codesandbox? Is it a TLA error?

image

josepot commented 1 year ago

What is the error you are getting on codesandbox? Is it a TLA error?

image

Try creating a TS sandbox from scratch, then install capi and then try to reproduce the code reported in this issue (which I wanted to illustrate with a codesandbox/stackblitz, but wasn't able to 😞)... The result is this.

There are at least 2 problems in there: 1) Cannot find module 'capi' or its corresponding type declarations (and yes, moduleResolution is set to Node16) 2) SyntaxError: await is only valid in async functions and the top level bodies of modules