I am building a cli tool and it has a folder named template
which contains all the js templates required to create certain files. I install my tool globally with npm install -g
.
I created a separate directory to test this tool but half way through running the tool (when its time to create the files from templates) it give the error Error: ENOENT: no such file or directory, open './bin/templates/_app.ejs'
This is in my package.json
:
{
"name": "cliproject",
"version": "0.0.1",
"type": "module",
"main": "./bin/index.js",
"bin": {
"create": "bin/index.js"
},
"publishConfig": {
"access": "public"
},
...other code
}
and this is my folder structure (also someone please tell me how do you guys add the tree structure here):
>bin
| >templates
| | _app.ejs
| | _styles.ejs
| | _index.ejs
|
| index.js
| utils.js
The issue here was I was using local paths like:
renderTemplate("./bin/templates/_app.js");
instead you should be passing paths, including the current working directory (process.cwd()
)
renderTemplate(path.join(cwd, "bin/templates/_app.js"));