Windows specific bug: Using Construct <AppSyncApi...
# help
a
Windows specific bug: Using Construct AppSyncApi. When running
npm start
on windows, everything gets build and deployed fine. However when I do a GraqhQL query, the live lambda environment crashes
Copy code
Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: Cannot read property 'filename' of undefined","reason":"TypeError: Cannot read property 'filename' of undefined","promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: Cannot read property 'filename' of undefined","    at process.<anonymous> (D:\\Starlight\\node_modules\\@serverless-stack\\aws-lambda-ric\\src\\index.ts:48:19)","    at process.emit (events.js:375:28)","    at processPromiseRejections (internal/process/promises.js:245:33)","    at processTicksAndRejections (internal/process/task_queues.js:96:32)"]}
Works fine on MacOS and Linux
f
Taking a look
@Ahmed Moaz Asif is this error coming from ur datasource/resolver code, or from SST?
Copy code
TypeError: Cannot read property 'filename' of undefined
a
From my lambda datasource when runnign with npm start.
Passing a custom vpc to appSync default function props. ^^ works fine on mac and linux.
f
I see. Did it work without the VPC?
a
The appsync example works. My stack doesn’t. Even without specifying vpc.
f
I see. Can you show me where this error is coming from in ur code?
Copy code
TypeError: Cannot read property 'filename' of undefined
a
Copy code
import Note from "../entities/Note";

import { listNotes, createNote, updateNote, deleteNote, getNoteById} from '../libs/services/notes.service'

type AppSyncEvent = {
  info: {
    fieldName: string;
  };
  arguments: {
    note: Note;
    noteId: string;
  };
};

export async function handler(
  event: AppSyncEvent
): Promise<Note[] | Note | string | null | undefined> {
  switch (event.info.fieldName) {
    case "listNotes":
      console.log('Here there')
      
      return listNotes();
    // case "createNote":
    //   return await createNote(event.arguments.note);
    // case "updateNote":
    //   return await updateNote({ id: event.arguments.noteId, content: event.arguments.note.content});
    // case "deleteNote":
    //   return await deleteNote(event.arguments.noteId);
    // case "getNoteById":
    //   return await getNoteById(event.arguments.noteId);
    default:
      return null;
  }
}
Interestingly, the error occurs only if I use a method required from another file. Attaching Debugger in vscode and pausing on uncaught exceptions and viewing the original error's stack, the error occurs in the transpiled ssl artifact file
.sst\artifacts\dev-ahmed-starlight-backend-AppSyncStack-AppSyncApi-Lambda_notes\src\functions\notes.js
Copy code
if (alternateMethod || appRootPath == null) {
        appRootPath = path.dirname(requireFunction.main.filename);
 }
requireFunction is a function and so it can't read property filename of main
The definition of
requireFunction
Copy code
var requireFunction = typeof __webpack_require__ === "function" || typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : require;
f
Hey @Ahmed Moaz Asif thanks for digging into this. I managed to reproduce this issue on my end. We should have a fix real soon.
@Ahmed Moaz Asif can you try adding this at the beginning of the
main
function inside ur
stacks/index.ts
Copy code
app.setDefaultFunctionProps({
  bundle: {
    nodeModules: ["typeorm"],
  },
});
The error comes from this app-root-path library that TypeORM uses. And it doesn’t seem to be compatible with
esbuild
.
Give it a try and let me know if it works for you.
a
It works.
Thanks a ton for your help.