`ERR_UNKNOWN_FILE_EXTENSION` when running tests
Package version
@adonisjs/[email protected], [email protected]
Describe the bug
I'm looking to do some frontend templating using ejs, to avoid react etc. and keep things simple (or so I thought).
As part of my code that runs in the browser I've raw imported the EJS file
# resources/js/templates/node-position.ejs
import nodePositionTemplate from './templates/node-position.ejs?raw'
# vite.config.ts
export default defineConfig({
assetsInclude: '**/*.(html|ejs)',
});
The above seems to compile just fine when running via node ace build or node ace serve --hmr. However running node ace test yields the following error:
% node ace test
(node:42106) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
[ info ] booting application to run tests...
(node:42108) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Re-optimizing dependencies because vite config has changed
(node:42108) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Error: ERR_UNKNOWN_FILE_EXTENSION .ejs /Users/ketanpadegaonkar/code/meshtastic/paragliding-meshmap/resources/js/templates/node-position.ejs
⁃ defaultGetFormat
node_modules/ts-node/dist-raw/node-internal-modules-esm-get_format.js:93
⁃ defer
node_modules/ts-node/src/esm.ts:296
⁃ entrypointFallback
node_modules/ts-node/src/esm.ts:304
Reproduction repo
https://github.com/ketan/paragliding-meshmap
Hey @ketan! 👋🏻
Any reason to use ejs instead of the backed-in Edge template engine?
As per your issue, you are trying to compile your ejs file with Vite.
Vite is only used to compiled your frontend assets. Use directly node to compile your ejs like we are doing for edge.
// When using Edge
router.get('/', async ({ view }) => {
return view.render('welcome')
})
Hi @RomainLanz - thanks for responding. I'm looking to do some templating in the frontend, not looking to do this via backend. EJS is what I'm familiar with, and trying to avoid react/vue etc.
Gotcha. You want to use ejs with client-side JavaScript to make it easier to write vanilla components.
Doing so, I still believe you don't need to compile your template through Vite if you are purely client-side. If you know what you are doing you can try to add a Vite plugin to support ejs files: https://www.npmjs.com/package/vite-plugin-ejs
Closing since no answer from issue reporter.