Question

I'm just getting started with Component package manager. I understand that I can require in other local modules by adding the module to the local key in the component.json file, but what if I don't want to treat every file as a module?

In the (very minimal) documentation for Component, it's developer TJ says that I can add any other relevant scripts (that live in the same directory) to the scripts array. And yet, on doing so, I'm unable to require or reference any of the peripheral scripts' methods from my main file.

The require method fails on trying to load in the script, and any attempt to reference the methods or variables from that script from the 'bootstrap' file are futile. My build.js shows that the script has been compiled in, but I just can't seem to figure out the correct way to reference it from other scripts...

Help?

Was it helpful?

Solution

I just thought I'd post the answer to this question so anybody with the same problem can find it quickly/painlessly.

The answer is to reference the script with a pointer to it's current directory like so:

var script = require('./script.js');

Note the ./ at the beginning of the file name.

An easy mistake to make/rectify.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top