starknet.js icon indicating copy to clipboard operation
starknet.js copied to clipboard

starknet.js is not working from CDN

Open mohammedi-haroune opened this issue 3 years ago • 4 comments

I want to use starknet.js in a simple web app built with vanilla HTML/CSS/JS with nothing like npm, yarn, webpack, react ....

The first way that come to mind is to use a complied and minified Javascript hosted on some CDN which I did and got the following error in the browser console:

Uncaught ReferenceError: exports is not defined
    at index.js:28:23

Reproduction

Create an HTML file with the following content and open it in the browser, open the console in the developer tools to see the error

<!DOCTYPE html>
<html>

<head>
    <title>Example</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script>
</head>

<body>
    <p>This is an example of a simple HTML page with one paragraph.</p>
</body>

</html>

mohammedi-haroune avatar Sep 20 '22 07:09 mohammedi-haroune

Notices the same Issue when doing local npm link and run in browser js app. I suppose it is a build module type issue but didn't had time jet to tackle it.

tabaktoni avatar Sep 21 '22 12:09 tabaktoni

Notices the same Issue when doing local npm link and run in browser js app. I suppose it is a build module type issue but didn't had time jet to tackle it.

Yes. Same for me, I tried to build the npm package and use the the resulted index.js file and had the exact same problem. I also think this could be solved with some tsconfig.json tweaking, this is literally blocking the development of our project, do you have an idea about when could we expect a solution for it ?

mohammedi-haroune avatar Sep 21 '22 22:09 mohammedi-haroune

this is literally blocking the development of our project

as an open source project, we‘re always happy about contributions!

janek26 avatar Sep 21 '22 23:09 janek26

this is literally blocking the development of our project

as an open source project, we‘re always happy about contributions!

Sure, although I'm not a Javascript/Typescript dev myself I tried to solve the problem by Googling, Stackoverflow without success, I also reached out to some Frontend devs I know to see if they have anything to suggest, nothing worth sharing for the moment but I'll definitely contribute the solution If I found any

I'm also open for your directions and suggestions on what you suspect could be the issue or what I should learn/know to be able to debug it and fix it myself.

mohammedi-haroune avatar Sep 22 '22 07:09 mohammedi-haroune

+1

smichea avatar Oct 13 '22 03:10 smichea

If you need this feature ASAP there is a draft PR linked to this issue that can help you get unblocked. If you switch to the corresponding branch and execute npm run build -- --platform browser it should result in a dist/index.global.js file that can be used in the way described in the opening comment.

penovicp avatar Oct 28 '22 11:10 penovicp