Skip to content

Problem while setting up the project locally #345

@aayushman950

Description

@aayushman950

Summary

I’m trying to set up this repository locally following the instructions in the "Run Services Locally" section of the README, but I’m running into some issues.

Running the serverless invoke command gives unable to locate handler and module not found errors. I have managed to work around it and managed to run the project locally(steps included below), but I'm not sure if my approach is good.

Can you please review the errors and tell me if I'm doing something wrong? I’m not very familiar with the codebase yet, so I’d greatly appreciate any guidance on setting it up properly.


Steps to reproduce the error

  1. Cloned the repository.

  2. Created databases 'carbondbdev' and 'carbondbdevEvents'

Image
  1. Created backend/services/.env.local with the following:
DB_HOST=localhost
DB_PORT=5432
DB_USER=root
DB_PASSWORD=root
DB_NAME=carbondbdev
  1. Moved to backend/services and ran yarn run sls:install


5. Ran the serverless invoke command

serverless invoke local --stage=local --function setup --data '{"rootEmail": "root@root.com","systemCountryCode": "NP", "name": "NepalGov", "logoBase64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADUAAAAwCAYAAACxKzLDAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAa7SURBVGhDlZkLwqM2DIQD+e9/i96id+oB9k9Sj+QPD8JAdtpZv2RJgx+Q3eW/f/79PDqWZem1x2O1Onh/0lTlsi6b/Uftib36n8/n4/V6xfjzZ42+zzv9rG1M9Tqftuhj67pGKeATyA603HPADQQEqB+60EhuQkA9y+T79W7tpB4KkG/3EfHauETooSDm/X4HJcjtRUdYy8kVfGKIe667p+Z1t9v7TWGsUtSbuMfS2mIfX+SqtTWm5CE5SBQxzjCyOUE46rwCIvZCEltfK2Lbbqu0FxOCtj5hH/NODNhEaWvVc4SQ2RgBaiAXpzEx2mW73aP5lRkr2YjfO6zfqHdnJApqoNqOLTbBXdz0oxK2dn8w7n+GWKm6Co6zbeeOfZ9fJTvO0xE8rMv5nMEb3J4p4aUbpxPU4DUpieYCiXPUn3SU/YH4g7lDrviIeTU3orIalJ6g0+FOVdfVq1J2fvWu63gXCYxTB5oLBVYfG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EocDsBH/Htpz4cQHcUhv1skYjzHLwU58JBtPWQ1NW76at5MU91Lx0t1/Xx8zP+YctBcCgbnDo86ODYajNsV7l8tzIfWjJi9X8Doz2Yt+IMxD7dfnJACYVMdDhwHG+/ve1uruz0s7zXY0z/97lRZvWQg4Avzwuu+qz/80e/Ho//5AgrfG/Pxh11nDY/ddjirxZfuWhcpF92W72dBOousGK3UscnnSAIdX7fODSHq1qMnyoOJWFPNea3Uj34lEhfEY+rvtyKYzuyNbETVT/dfghrNmFIIIH62UMA8ZRhDwr0q5ozs7H7VTwhEu999RzJBlasZwkJmbCSGQ6wV5Dj+2iOENCpRJ2Ctz1R78929lVU+5CfL7gj2ErCEJbtFHQMwO3kQhwkIKj+LlvVE/RSYHsJ9KuNGPraZ1ImeSZM0Nh4R+U2YBXrfEoS9YAQ+LZ0sTPIr2wgcL+M9ZW6dihUG5KXSOozaNYZYzu2/+p8nS+BJIELOMMm6spIkCFPFHCmcgXHC5Eytl0j82ZU3Lwg8ha7BnGGKBdNXc3MoMAvgJyUjnBA4sDFAbbWDH7WEAZUj0+mgMqkYvMwVA+7npOIn6e+RFJ9kuQEksQYKhexyd2CnIHkKwX5PYX+LmFbGQkeuQAXU321PFugEJCHX4YV2vPxcuwvXUoXxVXv8FutgqTm8ZTsEOGJU6bNUZD64z3lN1kmmn0cYIInoyuAUwTJHoLYhj6p40ywuj2ei/DS4cKWZXn8D8F2QswYe/whAAAAAElFTkSuQmCC"}'

Expected Behaviour:

Database tables and root user get created.

Actual Behaviour:

Got the following error:

Compiling with Typescript...
Using local tsconfig.json - tsconfig.json
Cannot locate handler - src/setup/handler. not found
Environment: linux, node 18.20.8, framework 3.30.0 (local), plugin 6.2.3, SDK 4.3.2
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Error: Typescript compilation failed. Please ensure handlers exists with ext .ts or .js

Possible Reason: The handler exists in backend/services/libs/shared/src/setup/handler.ts but the setup handler in serverless.yml points to src/setup/handler.handler


Changes I made to make the project run locally:

Backend

Manually built the backend with yarn build using tsc and tsc-alias to handle path aliases, then run the precompiled JavaScript from dist instead of relying on Serverless to compile TypeScript.

Steps given below:

  1. In backend/services, ran yarn add -D tsc-alias to add tsc-alias to handle path aliases.

  2. Changed the build script in backend/services/package.json

Before: "build": "nest build"
Changed it to: "build": "tsc --project tsconfig.json && tsc-alias"

  1. Changed the path in backend/services/libs/core/src/app-config/app-config.module.ts

Before: path: path.join(__dirname, "/shared/src/i18n/")
Changed it to: path: path.join(__dirname, "../../../../libs/shared/src/i18n")

  1. Created a shared folder in backend/services/libs/shared/src with the following code:
exports.handler = async (event) => {
    console.log(`Started with: ${event.body}`)
}
  1. Ran yarn build. This creates a dist folder in backend/services

  2. Change all handler paths in serverless.yml to point to dist

  3. In serverless.yml, commented out the serverless-plugin-typescript:

plugins:
  # - "serverless-plugin-typescript"
  1. Copied the i18n folder from backend/services/libs/shared/src/i18n to backend/services/dist/libs/shared/src

  2. Now, running the serverless invoke command (this one) successfully added tables to both databases and created a root user in the system.

  3. Started the backend with sls offline --stage=local

Frontend

  1. Moved to /web and ran yarn install

  2. Changed VITE_APP_BACKEND in web/.env to:
    VITE_APP_BACKEND = http://localhost:3000/local

  3. yarn dev to run the frontend on http://localhost:3030/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions