khamake icon indicating copy to clipboard operation
khamake copied to clipboard

require() is not working for local scripts

Open sh-dave opened this issue 9 years ago • 2 comments

Currently it's not possible to require local scripts from within khafile.js.

khafile.js

const myscript = require('./myscript.js');
let project = new Project('xxx');
...
Creating Kha project.
{ Error: Cannot find module './myscript.js'
...

I guess this is due to how the projectfile is run in https://github.com/KTXSoftware/khamake/blob/master/src/ProjectFile.ts#L24 as it only gets very limited access to anything from the executing script.

sh-dave avatar Nov 30 '16 10:11 sh-dave

I guess it's because the current script dir is something else when the code executes. But should be possible to fix that...

RobDangerous avatar Nov 30 '16 18:11 RobDangerous

Found a workaround for now: just create a node_modules folder in your project root drop myscript.js there and then you can require('myscript.js') in khafile.js and it gets picked up.

sh-dave avatar Dec 08 '16 12:12 sh-dave