I am currently working on a NodeJS project that utilizes Webpack for bundling and Express for serving. Whenever a user visits the root domain, they are served an index.html
file containing a <script>
block in the footer with a type
of module
.
index.html
<!DOCTYPE html>
<html lang="en">
<head><!--content--></head>
<body><!--content--></body>
<footer>
<script type="module">
import MyService from './services/my';
// Use MyService
</script>
</footer>
</html>
Additionally, I have a my.js module located in the specified directory:
export default class MyService { ... }
When I build, start, and access my app (on localhost), I encounter an error in the console:
GET https://localhost:3009/services/my.js net::ERR_ABORTED 404 (Not Found)
It seems like my app is trying to locate the module via the URL instead of the code tree. Do I need to make any adjustments to my configuration to resolve this issue? Should I set up a separate entry point with Webpack? Any advice would be greatly appreciated. Thank you.