How to make npm modules compatible? #4581
Replies: 1 comment
-
Posted at 2015-04-17 by @gfwilliams Hi, The Espruino Web IDE usually looks in www.espruino.com/modules to find anything you've I just tried yours and it doesn't seem to work though - it's loading I haven't really done much work on NPM support, because most modules I looked at in NPM pulled in loads of dependencies and filled up the available memory - it could be that something has changed or I'm just not dealing with that particular case (the NPM loader's code is here) Another simple hack is just to stick the JS file's URL into require:
You can use localhost and a server, or you can use the 'project' feature in the Web IDE so that you can pull single files directly off a directory on your hard disk. Posted at 2015-04-17 by WebReflection uhm ... OK, thanks for the info. If I load it manually I get this error:
And looking at "official" modules I see It is quite common in Back to the fragmentation quick chat we had on twitter few days ago, having a different way to export for Espruino only would be somehow weird for most modules. I understand not every module will or should run in here, but I've been coding small modules since about ever and I'm curious to see what works here and how well. Thanks Posted at 2015-04-17 by @gfwilliams
Posted at 2015-04-17 by WebReflection OK, I wrote it not so clear indeed ... This is current/common status in
With current Espruino there's no way to directly export the object or the function, you can only attach properties to the Will this be improved to reflect common Thanks Posted at 2015-04-17 by @gfwilliams Right now the following works:
In fact I think even prefixing your module with But yes, I'll make sure that there's a modules variable - I've filed a bug Posted at 2015-04-17 by WebReflection
watch out, the
If you require a file like that, the log is Posted at 2015-04-17 by @gfwilliams Ahh, interesting - thanks. I'll make sure I check that's the case here too |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-04-17 by WebReflection
I'm, trying to
require
quite small modules through the Web IDE and on a Pico board 1v76No matter what I require, it's always the same:
I'm requiring on the right side, which is also graphically telling me every time that module hasn't been found.
this module is just an example, but reading the documentation I also spot the following:
In node.js and io.js world I've never thought minification would have been useful but I understand its value for small devices like the Espruino Pico.
However, I wonder if there's any official procedure able to make a module compatible with the pico: any specific field in the
package.json
file? Should the main file be the one minified, called.min
?Please let me know what I should do in order to write Espruino Pico capable code, thank you.
Beta Was this translation helpful? Give feedback.
All reactions