Skip to content

Regression: Version 3.49.0 and upwards are not able to parse serverless.ts when using tsconfig.paths #61

Open
@AlesioSinopoli

Description

@AlesioSinopoli

Hi all,

A bug/regression was introduced in version 3.49.0. Previous versions were able to successfully parse serverless.ts config files that have imports which rely on tsconfig paths.

Details

At the top of my serverless.ts file I have the following import statement:

import { apiGatewayResources } from '@/resources/apigateway/serverless';

In my tsconfig.json file I have the following paths configuration:

"paths": {
      "@/database/*": ["src/database/*"],
      "@/helpers/*": ["src/helpers/*"],
      "@/libs/*": ["src/libs/*"],
      "@/services/*": ["src/services/*"],
      "@/testing/*": ["src/testing/*"],
      "@/types/*": ["src/types/*"],
      "@/v1/*": ["src/v1/*"],
      "@/v2/*": ["src/v2/*"],
      "@/resources/*": ["resources/*"],
      "@/migrations/*": ["src/migrations/*"]
    }

When I run sls offline start, I get the following error:

Error:
Cannot parse "serverless.ts": Initialization error: Error: Cannot find module '@/resources/apigateway/serverless'
Require stack:
- /Users/alesio.sinopoli/Desktop/Projects/api/serverless.ts
    at Function._resolveFilename (node:internal/modules/cjs/loader:1244:15)
    at Function.resolve (node:internal/modules/helpers:146:19)
    at jitiResolve (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/jiti/dist/jiti.cjs:1:187220)
    at jitiRequire (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/jiti/dist/jiti.cjs:1:189288)
    at import (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/jiti/dist/jiti.cjs:1:199778)
    at /Users/alesio.sinopoli/Desktop/Projects/api/serverless.ts:1:218
    at eval_evalModule (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/jiti/dist/jiti.cjs:1:196325)
    at jitiRequire (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/jiti/dist/jiti.cjs:1:190233)
    at Function.import (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/jiti/dist/jiti.cjs:1:199778)
    at parseConfigurationFile (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/osls/lib/configuration/read.js:62:42)
    at module.exports (/Users/alesio.sinopoli/Desktop/Projects/api/node_modules/osls/lib/configuration/read.js:145:29)
    at /Users/alesio.sinopoli/Desktop/Projects/api/node_modules/osls/scripts/serverless.js:186:28
    at /Users/alesio.sinopoli/Desktop/Projects/api/node_modules/osls/scripts/serverless.js:194:13

Root cause of the regression

The following PR #30 made changes to how the serverless.ts config file is parsed. It removes ts-node and introduces jiti instead.

At the moment, jiti does not support tsconfig.paths, so it's unable to parse any files that contains import paths defined in that way.

Closing Thoughts?

Many developers use tsconfig.paths in their projects. This change can affect their experience and make them unable to upgrade to newer versions of osls without re-factoring code and dropping their tsconfig.paths entirely.

Not sure what can be done to solve the problem at the moment without reverting the new feature introduced in 3.49.0, besides waiting until jiti adds support for tsconfig.paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions