My current challenge involves importing an HTML file using
import template as "./template.html"
as a string to be displayed to the user through Express's res.end(template);
function.
To facilitate this, I have set up an index.d.ts
file in the main directory of my project with the following contents:
declare module '*.html' {
const value: string;
export default value;
}
Although I can import template.html
successfully, I encounter an issue when running the program. The error message indicates:
/home/koen/Workspace/xyz/src/template.html:1
<!DOCTYPE html>
^
SyntaxError: Unexpected token <
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/koen/Workspace/xyz/out/index.js:11:41)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
It seems like there is an attempt to interpret the HTML as JavaScript code, leading to this unexpected behavior. Any insights or suggestions on why this might be happening? I'm currently at a roadblock...