What is the best way to add new npm packages?

If you want to use something at runtime put it into dependencies instead.

As Marcel mentioned that entire import { X } from Y is really package-specific - X and Y are something you find in the documentation of that package. There’s no rule for ā€œin somePackage it’s always called SomePackageā€ or so, it’s really up to authors; many packages expose multiple things.

Here’s a good summary of some patterns that you may run into - the specific one for each package will be in the package’s docs: import - JavaScript | MDN

That’s useful to know what the devDependencies are for, I got the dependencies muddled

by user 103054507105067008

Useful link also, I think I’ll be stuck at this for a while as the errors aren’t clear as I keep getting '/node_modules/.vite/deps/node_modules_depthkit.js?v=292aaf0e' does not provide an export named 'default'

by user 103054507105067008

This somehow worked import DepthKit from "depthkit/src/depthkit.js";, I now get errors about the use of const glsl = require('glslify'); for let rgbdFrag = glsl.file('./shaders/rgbd.frag'); as TypeError: glsl.file is not a function which I assume is an issue with using require at runtime which has led me to look into using ā€˜browserify’ to resolve ā€˜require’ in the browser. I hope I’m on the right path here…
https://github.com/browserify/browserify#example

by user 103054507105067008

I’m going to go back to square one and run their package as its own Three.js project and see if I can update its dependencies like Three.js then try to bring it back into Needle… my head hurts lol

by user 103054507105067008

It sounds like you’re mixing import and require, you’ll most likely only have import statements. If you try using glsl.file( then you need to import glsl from somewhere.

Looks like people had similar issues with using DepthKit as proper module: Getting `depthkit__WEBPACK_IMPORTED_MODULE_5___default.a is not a constructor` on imported npm module instantiation. Ā· Issue #11 Ā· juniorxsound/Depthkit.js Ā· GitHub

Going to try their fix, I wasn’t aware that npm packages weren’t all meant to run as modules which is probably where I fell over setting up. What a mess of an ecosystem in npm!

by user 103054507105067008

Haha yeah, basically over the years many standards emerged and only in recent years it’s converging on the final proper ES6 standard for how to modularize JavaScript code.