ScriptCraft

ScriptCraft

14.6k Downloads

require() unexpected behaviour

leumasme opened this issue ยท 1 comments

commented

I wanted to make my own module.
I created a folder called temmmod in the modules folder and a file called temmmod.js inside it.
when i now try to require("temmmod") it doesnt work but asks if i meant modules/temmmod/temmmod
When i then change require("temmod") to require("temmod/temmod.js") everything works. understandable.
but then... why does require("utils") work? the utils moudle is in modules/utils/utils.js, but require still finds it. Why does require-ing a folder work for utils but doesnt work for my custom module?

commented

The utils directory contains a package.json file which points to utils.js. If you don't have a package.json file in your directory, you should name your main file index.js.