https://serverless-stack.com/ logo
#help
Title
# help
d

Dan Van Brunt

12/09/2021, 9:13 PM
Never saw this SST error before…
Error: Cannot find a "tsconfig.json" in the function's srcPath
t

thdxr

12/09/2021, 9:15 PM
Weird hm
d

Dan Van Brunt

12/09/2021, 9:15 PM
one odd thing is that there seems to be TWO
.build
folders being created…
FYI, I made this change to
tsconfig.json
Copy code
{  
  "compilerOptions": {
    "typeRoots": ["./src/_types", "./node_modules/@types"],
  },
  "extends": "@tsconfig/node14",
  "include": ["stacks", "src"],
}
Want to see anything else @thdxr? I also removed the eslint config from the package.json in favor of
.eslintrc.js
Copy code
module.exports = {
  root: true,
  extends: [
    'serverless-stack',
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'prettier',
    'plugin:prettier/recommended'
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 2019,
    sourceType: 'module',
    tsconfigRootDir: __dirname,
    project: './tsconfig.json',
    files: '*.ts'
  },
  rules: {
    '@typescript-eslint/no-floating-promises': ['error'],
    '@typescript-eslint/no-unused-vars': ['warn', { 'argsIgnorePattern': '^_' }]
  }
}
hmmmmm I wonder if that
tsconfigRootDir: __dirname,
is the issue? thought I had this working before though.
so narrowed down that the
sst.Api
code was doing it…. where as I also have two other
sst.Function
s that are working/building fine
t

thdxr

12/09/2021, 9:22 PM
I actually just rewrote all of this so I don't think this situation can happen anymore
d

Dan Van Brunt

12/09/2021, 9:23 PM
just widdled down the above to this and it works.
Copy code
const api = new sst.Api(this, 'Api', {
      routes: {
        'GET /githubwebhook': 'src/githubwebhook.handler',
      },
    })
but this fails…
t

thdxr

12/09/2021, 9:24 PM
So the issue is "srcPath" is basically signifying what is your "project root"
Specifying
srcPath
sets that to your project root and all builds happen relative from there (which is why you get another .build) folder
I in the next version it's fixed so you don't get another build folder and also you don't necessarily need another tsconfig in your srcPath
but you probably should place one there
d

Dan Van Brunt

12/09/2021, 9:28 PM
hmmm but why would these be any different….
Copy code
new sst.Api(this, 'Api', {
  routes: {
    'GET /githubwebhook': `src/githubwebhook.handler`
  }
}

new sst.Api(this, 'Api', {
  routes: {
    'GET /githubwebhook': {
      function: {
        srcPath: 'src/',
        handler: 'githubwebhook.handler',
      }
    }
  }
}
should I just be doing this?
Copy code
new sst.Api(this, 'Api', {
  routes: {
    'GET /githubwebhook': {
      function: {
        handler: 'src/githubwebhook.handler',
      }
    }
  }
}
ya that worked.
t

thdxr

12/09/2021, 9:34 PM
srcPath is what makes it different, it shouldn't be used if you just want a prefix on the handler path
we probably need a better name for it
projectRoot or something
d

Dan Van Brunt

12/09/2021, 9:34 PM
kk…. my bad. sorry bout that
t

thdxr

12/09/2021, 9:45 PM
np I went through the exact same thing as you initially
d

Davide Ungari

12/15/2021, 10:48 PM
just for your information I had the same issue... now that I fully read the documentation I understand the thing is that an example set me on a wrong path... for sure better naming would help
5 Views