I have tried a few ways to put a module in my local project. In the web ide I have set a folder for a project, this created a bunch of folders, one of them modules - I have tried to NPM install a module gsap there but I cannot require this with:

var gsap = require('gsap');

I thought maybe it doesn't need to be in node_modules folder so I took out the gsap folder and only that is in modules, still can't find it.

I copied the min.js file to modules folder, still cannot require it there.

Both of these examples work if I use the cmd to run node and the require('gsap'). What is the correct way to require a module from modules folder in a project?

I'm sure this is your case as was explained, but just in case:
Verify the module 'gsap.js' is in a sister 'modules' folder adjacent to the code file in the 'projects' folder. Both children of the sandbox parent folder.

I ran into a similar issue on Windows10 and played with this for quite a while before finding a solution. See #19

If this is the case, sounds like the same issue I had. I would read over what I went through. The only suggestion I have (I'm an end user just like yourself) is to create a new folder (the sandbox) in the root of drive 'C'. Change the sandbox location (Settings >> Project) to match that folder. Then using the 'projects' button on the IDE, accept that default in order for the IDE to create it's own mappings. Then using Windows, go back and patch the code file and place the module file in the IDE created folders.

OK so this is now working, thank you for pointing me in the right direction with the question if I had written this module myself!!!

I created a quick module to check and that was indeed loaded correctly, which made me think ahhhh I need to rename the downloaded module so that the filename matches what the Espruino is looking for, this isn't necessary using node_modules as it uses the folder name as the mapping I believe.

So it is now loading the module as expected.. Sorry for the confusion and thanks for the support.

Didn't use node_modules anywhere. It works fine regardless of where my sandbox folder is in the two cases mentioned previously.

I think you're right about not being able to use this on Espruino though as I can't seem to call any functions on it.

I was hoping to use it with the WS2811 lights, I used to do all my anims manually with setInterval but I've extensive knowledge of this library from doing frontend dev over the years and had an idea to Tween values using this as it's so powerful, maybe it will work out or maybe it won't...

PS. It can be used on nodejs so maybe there's a way to get it to play with Espruino.

Do you recall how you learned about 'node_modules' or used it (see #1) for this post?

Just trying to provide those that work on the edits of the IDE more information. In my case it was an error that popped up, despite never using, or creating, or even having any knowledge of that folder word. I'm sure they would be curious how a separate unique user had the same occur on their system, doing nothing more than attempting to access a module.

Ah so originally when I wanted to use the 'gsap' module, I thought I'd install it in the modules folder that was created by the sandbox project thingy. To do this all you need to do (as long as you have nodejs installed of course) is:

npm install gsap

This creates the 'node_modules' folder with another folder called gsap inside, inside this is all the files associated with the gsap module.

Then in node at least, you just require it and off you go...

What I hadn't realised (but do now after reading the forums) is that there was a beta NPM setup but that was dropped, possibly unrelated to my issue anyway (I'm digressing here) but I thought maybe the Espruino expected local modules to reside in a 'node_modules' folder, but it doesn't.

Yep, thanks, it does for me, no confusion on your part. Ahhhh, now we have the needed missing bit of information. I also, at some distant time past, installed NPM. So, maybe there is a conflict with the IDE somehow, relative pathing when using modules. Food for thought @Gordon, and yet another item to add to your all ready lengthening to do list . . . see #8 #2 response

GSAP is a JavaScript library for creating high-performance animations that work *** in every major browser ***.

The code runs in the browser and the node.js / Web server. Even though Espruino (-Wifi) can work as a a Web server, it is not a node.js server.

If you implement a Web server on your Espruino-Wifi - based on https://www.espruino.com/WebServer - and implement the pulling of files according to the http(s) request request urls from the SD card, you may get something working (in your browser). You have to used the SD card because Espruno's memory is just to small to keep all the files in memory. Espruino is then the server for the resources the browser needs. Even if you get node.js basics server-side - on Espruino-Wifi - going, it just lacks the resources...

It would be help full to explain what you want to achieve from a birds point of view.

Yes thank you @allObjects. I wasn't aware of 'gsap' or it being a publicly available source and at that (#2 above) time made the assumption that 'gsap'(an unusual name) was created by Coder2012 and was just having difficulty loading the module. We cleared up usage in #7 above, and @Coder2012 is aware of it's limitations.

There is information available about using node.js / npm modules. After all, Espruino follows the node.js style of handling modules. Second one is very insightful conversation with explanations from @Gordon.

It would be help full to explain what you want to achieve from a birds point of view.

So when I first got the original Espruino I created animations for my LED lights using setInterval functions.

The code quickly became verbose as I added more patterns. I experimented back then trying to use gsap but there wasn't enough memory.

When I decided to look again and was amazed that the Espruino WiFi version was out with more memory I thought my idea could work out.

Gsap is designed for the browser as it transitions elements in the DOM but can also transition values on objects you create yourself, therefore you're not restricted to just DOM objects or the window object in the browser.

I've since looked at smaller libraries that could work as I want to interpolate between values to use on these lights, the power of a tween library is that it has various helper functions like repeat, reverse and yo-yo to aid with creativity.

@Coder2012, very interesting and good to know. Actually I was looking for something like that for similar purposes, like driving multiple chains of RGB LED strings and RGB LED cubes:

Gsap is designed for the browser as it transitions elements in the DOM but can also transition values on objects you create yourself, therefore you're not restricted to just DOM objects or the window object in the browser.

May be taking gsap apart and use only the pieces that are needed, could be a starting point. From other experiences though I know that pretty quickly Espruino runs out of steam... and a minimum setup is more in the realm of recent model of Raspberry Pi, even though some stuff can be 'native-d down into Espruino guts' using compiled. Most likely, you will end up writing it natively and add it to the Espruino firmware with control-APIs for the JS side, like GPUs in an end point device have APIs exposed thru the Browser w/ JavaScript language binding (for feeding data and commands and ('source') code).

@Coder2012 glad you got this sorted - kinda. When you require something in Espruino it just grabs that single file as you named it. In something like Node.js it'll look in node_modules, find the folder with that name, then look in package.json and then load the file that it references - so dragging something directly off NPM is super unlikely to work.

Sadly the removal of NPM support in the IDE was because the vast, vast majority of modules on NPM are just too big to be usable. It was just super-confusing for everyone. It may end up getting re-enabled with some tree-shaking support that would hopefully be able to strip things back down a bit though.

Crazily it looks like TweenLite is actually bigger than Tween. On Espruino you can pull in Tween as-is - you just require some simple wrapper functions:

@Robin I think this is basically unrelated to your problems. NPM doesn't interfere with the IDE or anything like that. As far as I can tell from the issues you posted to date, your problems were either with how you used the modules you defined, or your use of ES6 classes which while supported by Espruino aren't handled properly by the minifier the IDE uses yet.

Post a reply

Bold

Italics

Link

Image

List

Quote

code

Preview

Formatting Help

Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.

Tips:

Create headers by underlining text with ==== or ----

To *italicise* text put one asterisk each side of the word

To **bold** text put two asterisks each side of the word

Embed images by entering: ![](https://www.google.co.uk/images/srpr/logo4w.png)That's the hard one: exclamation, square brackets and then the URL to the image in brackets.

* Create lists by starting lines with asterisks

1. Create numbered lists by starting lines with a number and a dot

> Quote text by starting lines with >

Mention another user by @username

For syntax highlighting, surround the code block with three backticks:

```
Your code goes here
```
Just like Github, a blank line must precede a code block.

If you upload more than 5 files we will display all attachments as thumbnails.