Preact-cli: Build process fails to locate custom template

Created on 22 Aug 2019  路  11Comments  路  Source: preactjs/preact-cli


Do you want to request a _feature_ or report a _bug_?
Bug

What is the current behaviour?
Upgraded to version 3.0.0-rc.5 and build command with custom template file fails. Uninstalled and returning to version 3.0.0-rc.4 resolves the problem

If the current behaviour is a bug, please provide the steps to reproduce.
The build command I was using is: preact build --template src/template/defaultindex.html

What is the expected behaviour?
Build succeeds

If this is a feature request, what is motivation or use case for changing the behaviour?

Please mention other relevant information.
Error on build:
脳 ERROR Error: ENOENT: no such file or directory, open 'C:\Users....\node_modulespreact-cli\lib\lib\webpack\src\template\defaultindex.html'

Please paste the results of preact info here.
Environment Info:

System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 10.15.2 - C:\Program Files\nodejs\node.EXE
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 42.17134.1.0

All 11 comments

confirm this issue

I can confirm this with 10.0.0-rc.1 and 3.0.0-rc.5.
It seems that cli tries to access the relative template path from "node_modules/preact-cli/lib/lib/webpack/" instead of the project root.

Workaround: if you use an absolute path with --template it still works, relative path with "../../../../../" will not work.

Since now we have the option of just keeping the template.html in src, may be we should move away from --template flag.

// @ForsakenHarmony @developit @lukeed @reznord

I've found this option pretty useful to serve up different templates. It'd be good to restore the previous behavior if possible.

@sampotts can u elaborate your use case a bit so we can justify the restoring

don't really see why we should remove it if it's useful for someone

TBH my only concern was that we'll end up having two way to do exact same thing.
No strong preferences. We should totally fix it if it still has a use case

@prateekbh I may be using it wrong but I have several different test pages to render simple preact components while in development:

"scripts": {
    "dev": "preact watch --template ./path/to/templates/index.ejs",
    "dev:store": "preact watch --template ./path/to/templates/store.ejs",
    "dev:product": "preact watch --template ./path/to/templates/product.ejs"
}

It's been working fine previously but if there's a better solution I'm all ears.

This was fixed in #878, will be in next release

@prateekbh Awesome, cheers! 馃帀

@sampotts I use templates the same way:

"dev": "preact watch --template ./path/to/templates/index.ejs"

But currently on rc.5 this functionality searches my node modules folder instead of the package directory. Does this method still work for you?

Will this begin to work again once the next rc is released?

Was this page helpful?
0 / 5 - 0 ratings