wobsoriano / elysia-autoroutes

File system routes for Elysia.js.
MIT License
112 stars 8 forks source link

bug: TypeError: undefined is not an object (evaluating 'fs.existsSync') #5

Closed fellipeutaka closed 1 year ago

fellipeutaka commented 1 year ago

When I try to build my project, I got this error:

TypeError: undefined is not an object (evaluating 'fs.existsSync')

My package.json:

{
  "name": "server",
  "version": "0.0.1",
  "main": "dist/app.js",
  "type": "module",
  "scripts": {
    "start": "bun run dist/app.js",
    "dev": "bun run --watch src/app.ts",
    "build": "bun build src/app.ts --outdir ./dist"
  },
  "dependencies": {
    "@elysiajs/cors": "^0.6.0",
    "elysia": "^0.6.23",
    "elysia-autoroutes": "^0.2.2"
  }
}

My src/app.ts:

import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";
import { autoroutes } from "elysia-autoroutes";

const app = new Elysia();

app.use(cors());
app.use(
  autoroutes({
    routesDir: "./routes",
  })
);

app.listen(3333, ({ hostname, port }) => {
  console.log(`Server is running at ${hostname}:${port}`);
});

export type ElysiaApp = typeof app;
export type GetHandler = Parameters<typeof app.get>[1];
export type PostHandler = Parameters<typeof app.post>[1];
export type PutHandler = Parameters<typeof app.put>[1];
export type DelHandler = Parameters<typeof app.delete>[1];

My unique route (src/routes/index.ts):

export async function get() {
  return { hello: "world" };
}

My tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "NodeNext",
    "types": ["bun-types"],
    "removeComments": true,
    "noEmit": true,
    "importsNotUsedAsValues": "remove",
    "isolatedModules": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "alwaysStrict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "allowUnusedLabels": true,
    "allowUnreachableCode": true,
    "skipLibCheck": true,
    "verbatimModuleSyntax": true
  }
}
wobsoriano commented 1 year ago

Hi, please consider upgrading to v0.4.0 and check the docs. Thank you!

Feel free to reopen if you still encounter this issue :)