#Trying to get Metaballs JS to work but it says it's typescript

8 messages · Page 1 of 1 (latest)

misty pasture
#

hi I'm trying to get this code to work:
https://github.com/MrToph/metaballs-js/tree/master/packages/metaballs-js

i created a boilerplate html5 file with a link to script.js

inside the JS file Have the exact code

import initMetaballs from "metaballs-js";

const options = {
numMetaballs: 100,
minRadius: 3,
maxRadius: 7.5,
speed: 10.0,
color: '#ff0024',
backgroundColor: '#121212',
useDevicePixelRatio: true
}

const cssSelector = '#canvasId'
initMetaballs(cssSelector, options)

But when I try run this using VScode I get this error in Chrome:

SyntaxError: Unexpected identifier 'initMetaballs'. import call expects one or two arguments.

GitHub

Monorepo for all the official metaballs-js libraries. - MrToph/metaballs-js

grand token
#

@misty pasture need more info
did you just put the code in a JS file and included that JS file in a <script> tag in your HTML?

#

make sure the type of script you import is an ES module <script type="module" src="script.js"></script>

#

what bundler are you using?

#

if you simply try to run import initMetaballs from "metaballs-js"; in the browser, it won't work
the browser doesn't know how to resolve "metaballs-js"
you either need to bundle your code, or use import aliases

misty pasture
#

ah wow! yeah I just put the JS file and included it in a script tag

#

I'm not using a bundler, sorry I'm totally clueless with this,

#

I'll try import aliases