I’ve created a simple TS project with the following file structure:
root/
├── package.json
├── public/
│ ├── images/
│ ├── index.html
│ └── index.js
├── src/
│ └── index.ts
└── tsconfig.json
Where index.js
is the compiled index.ts
. The .ts
file contains a single hello world console log.
In index.html
I have the following line in my header tag:
<script src="../dist/index.js"></script>
Starting the server with http-server and opening the index.html
file throws a 404 error for GET /dist/index.js
.
However, moving index.js
to the public folder and changing the script tag source to "index.js"
makes it run perfectly fine. Moving index.js
to the root folder and making the source ../index.js
doesn’t work though.
To my understanding, ../
is supposed to refer to the directory above the current directory, so I don’t know why this wouldn’t work.