Open isaif opened 1 year ago
This is one of the major issues of typescript. You need to use some other tools to to copy those files.
cc @fastify/typescript
In my projects, I moved away from tsc
as a compilator because of these limitations: I use it only as a type-checker before running https://github.com/egoist/tsup. Maybe we should move the starter to something similar. @fastify/typescript, thoughts?
It doesn't matter if you are using tsup
or tsc
for this issue.
You should not place any static file inside the TypeScript
source code.
Or if you do, please do not specify the
Edit: remove outDir
, so both source code
and transpiled code
inside the same folder.outDir
doesn't work because of how it detect code changes. Move the static file to separate folder.
What I meant is that is metter of providing out of the box a way to copy static files from src to dist/build folders during the "compilation" process. Otherwise, we should add a paragraph that explains to put static files inside a folder outside the src. WDYT?
What I meant is that is metter of providing out of the box a way to copy static files from src to dist/build folders during the "compilation" process.
I thought it is the fundamental knowledge of using TypeScript
.
I believe all of the TypeScript
transpiler do not copy static assets to the destination folder by default.
Otherwise, we should add a paragraph that explains to put static files inside a folder outside the src. WDYT?
Yes and no. It is good to explain some special case in document, but just afraid if the same issue happened for others plugin. The document will be hard to read and understand.
I did create a directory "public" at the root. I was getting the same issue of missing static files.
Then I tried creating a static file inside the"src/routes" to see if it fixes the issue as I was unaware of the underlying cause.
Documentation regarding the recommended way of serving static files when using typescript will be helpful.
I think I'm having the same issue as I have a /build
folder where the outDir is placing the js files but with this setup:
server.register(fastifyStatic, {
root: path.join(__dirname, 'public'),
prefix: '/public/',
});
it can't read from the /public
folder
Prerequisites
Fastify version
4.0.0
Plugin version
5.7.1
Node.js version
v19.3.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
manjaro
Description
I have generated a project with typescript support and installed
fastify-static
to servehello.html
file at the root url.I am getting this error
Route GET:/hello.html not found
on log when trying to access the root on browser. On browser I get{"message":"Route GET:/hello.html not found","error":"Not Found","statusCode":404}
I have checked the
/dist
directory and it doesn't have thehello.html
file in it. I tried to delete thedist
directory and then restart the server usingnpm run dev
but it doesn't solve the issue.But when I tried to create a project without typescript it works as expected.
src
directorydist
directoryroot.ts
Project without typescript
Directory structure
root.js
Most likely I am making some mistake causing this issue but I want to be sure. Thanks.
Steps to Reproduce
Generate project
typescript support
without typescript
npm i @fastify/static
hello.html
file in/src/routes/
root.js
orroot.ts
in/src/routes/
Expected Behavior
I want to serve
hello.html
in the root URL.