3d-dice / dice-box

3D Game Dice for any JavaScript App
https://fantasticdice.games/
MIT License
134 stars 28 forks source link

How to use 3D dice in a Node app with express? #64

Closed mlordelo closed 1 year ago

mlordelo commented 1 year ago

Hello! First, I would like to thank you for this module, it is awesome!

I am creating a Twitch bot for D&D campaigns and I would like to use the module to create an overlay displaying the dice roll when the chat type a command.

I installed the module and I am trying to import it into my node app, but I am getting some errors like:

 Uncaught SyntaxError e:\Projetos\3Dice\node_modules\@3d-dice\dice-box\dist\dice-box.es.js:702
export { deepCopy as d, WorldFacade as default };
^^^^^^

SyntaxError: Unexpected token 'export'

I tried to add the "type": "module" in the package.json but it is not working. Sorry if this is not the best place to ask it, but could you please give me some help to import and use the module in my node app?

Thanks in advance!

PS: Sorry about my English, this is not my first language lol

frankieali commented 1 year ago

Hi @mlordelo. I'm sorry I missed this post. I'd still like to help if I can. Were you ever able to work your issue out?

mlordelo commented 1 year ago

Hi @frankieali. No problem. No, I wasn't. I had to stop working on the bot due to other priorities, but I would like to create an overlay and integrate dice-box into the bot.

I'll be working on this bot again this week.

I am new on node/javascript development and I've tried what I found about the error (adding the type = module in the package.json) but I couldn't solve the issue.

Thanks in advance!

frankieali commented 1 year ago

I'd be curious how you've set up your dev environment. Are you running your code through a bundler at all? I've been bootstrapping my apps with Vite lately. Now that I think about it, I recall having issues running dice-box.es.js as an es6 module. Perhaps due to the web workers it's bundled with. I would say try setting up your project with Vite and I'll see if there's something I can do about es6 modules in the meantime.

mlordelo commented 1 year ago

I created a basic node app, installed the dice box, and imported it (just a simple app to try to use it).

My goal is to install dice box in another app which is a twitch bot with commands to roll dices and to take cards from critical success/fail decks (there is an overlay to show the card in live).

I will try to use Vite. Thanks for the help, @frankieali!!

frankieali commented 1 year ago

Hey @mlordelo I did find an issue in the code that causes it to break in strict mode. That been fixed. It took me a few attempts to get the build right. The latest is @3d-dice/dice-box@1.0.8 I set up a new demo that shows how to use the library without having to install anything dice-box from CDN Hopefully the code fix or that new demo will help you get over the hump.

mlordelo commented 1 year ago

Hi @frankieali,

First, thanks for all your help!!

I managed to do what I was trying to, using that static template + socket.io to create the overlay for OBS, integrated into a Twitch chatbot with the command to roll the dices!