-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support tsconfig-paths and specify tsconfig*.json #28
Comments
Thank you @nhammond101 for that proposal. I'm not a TypeScript expect by any means, so it's hard for me to evaluate it - @medikoo what is your opinion here? It looks like it might be touching some of the parts of the codebase that you were working on recently. |
I've got a PR open, but trying to create tests is proving tricky so any help appreciated, specifically the testing of node modules required. One thing I'm concerned about is documenting the peer dependencies required for typescript support that I'm proposing. It'll need typescript, ts-node (as it does currently), with my change also needing tsconfig-paths. |
@nhammond101 thanks for raising this issue. To avoid increase of the maintenance cost on our side we would prefer to no host any further TypeScript specific solutions in context of https://github.com/serverless/serverless/ repository. Note that support for @fredericbarthelet do you understand the issue? Do you think it's possible to address the use case externally, without touching Framework core internals? |
Thanks @nhammond101 and @CorentinDoue for reporting the issue. It would indeed be of great value to TS developers to be able to take advantages of tsconfig-paths. With Serverless current process, handling TS related configuration requires to update the service file reading script located in
In order to be able to handle configuration parsing script other than @medikoo, if you'd like to address this specific TS feature outside of serverless/serverless scope, it would require some heavy lifting, moving the configuration reading process away from @medikoo @pgrzesik, would you like me to propose such a solution where configuration parsing would actually be part of the command lifecycle or does this seem to be too big of a change to be undertaken at this stage ? |
A bit more digging:
"ts-node": {
"require": ["tsconfig-paths"],
} to the tsconfig.app.json should work (i've traced the require all the way through to ts-node), but i'm still seeing |
So minor step forward - changing "ts-node": {
"require": ["tsconfig-paths"],
} to
does seem to help. I need to some more digging as the serverless-webpack plugin is throwing an error about a missing Serverless:
Serverless: Invoke webpack
Serverless: Invoke webpack:validate
Failed to load /Users/nick/Projects/apps/basic-auth/tsconfig.app.json: Missing baseUrl in compilerOptions
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin |
@nhammond101 you can try your config with TS 4.1. Using a baseUrl is not required anymore: https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#paths-without-baseurl |
i'm using 4.1 but dividab/tsconfig-paths#143 is causing the issue. The workaround is adding i'll create a fork of the typescript example and try and recreate the scenario. i think the base example works fine as the default tsconfig.json is being set and not overridden by the |
I'm wondering if using the webpack Environment plugin to unset |
I've pushed a example repo - https://github.com/nhammond101/serverless/tree/master/lib/plugins/create/templates/aws-nodejs-typescript
|
@fredericbarthelet I think that's a very good call. Still, as it's about adding a hook at the very early stage of command processing, where we do not have config parsed (so have no means to know what plugins are intended to be loaded), it cannot be really done via plugins. A solution that comes to my mind is.
I think given Having that users, may take advantage of full TS support, simply by configuring {
"serverless": {
"configResolver": "@serverless/typescript/config-resolver"
},
"dependencies": {
"@serverless/typescript": "1"
}
} ( Having that we could also move out current built-in TS resolution support from the Framework (ofc with next major), and then TS users may take advantage of unrestricted TS support which would be maintained in and provided purely in context of What do you think? (cc @pgrzesik) |
@nhammond101 thanks for your awesome work :) ! Do you think you can provide a PR to the template to :
I'm not sure about the requirement for 2 separate @medikoo noted, would be glad to work on such feature. I'll give it a go and see what comes through :) |
That's very welcome! I've realized that while we support Idea comes to my mind is to support extensions (core-level extensions, when plugins can be considered as high level functionality extensions) via {
"serverless": {
"extensions": ["@serverless/typescript"]
}
} And having that Currently I'm in a process of rewriting from scratch variables resolver, so to reduce implementation cost I'd expect the latter one to work only with this new resolver (let's not invest time at this point to try to adapt it into current implementation) What do you think? |
I think your suggestion makes a lot of sense @medikoo - it would also allow for a more modular approach to the Framework in general I believe. One question I have - what, in your opinion, should be exported by such |
I think it should support whatever extensions we have use case for. I'd start with supporting this use case, so simply I honestly hope that we will end at that point. Ideally, all that can be addressed via plugins is better if addressed via plugins |
@fredericbarthelet I think so, I've created a PR and added a small advanced section in the README that could form the basis for advanced configurations. |
@fredericbarthelet @pgrzesik @nhammond101 I've opened issue with implementation spec on Framework side serverless/serverless#9311 This should bring us closer to have that implemented. Let me know what you think |
I know a lot has changed in the last year, but I still can't seem to find a solution to this open issue. Does anyone know a workaround? |
bumped into this issue as well just now and hoping to find some solution to this. |
@severi Any chance you found a solution? |
I found two options for separating the serverless.ts tsconfig from application code:
|
Hello there, example dev command:
I prefer to keep my ts-paths inside a separated I'm in the situation where the "ts-node" key inside my tsconfig.json is already used by some custom ts-node based scripts inside my repository A custom I've also tried to author a feature that allowed to conventionally load an arbitrary |
just installing "tsconfig-paths" package in the same level where the tsconfig.app.json lies helped me |
I'm having an issue with my serverless.ts not picking up my type declarations for my custom configuration. so I'm unsure wether there is a related issue with |
Just confirming, adding
To my I'm using NX monorepo. serverless.ts is in an "app" that has a tsconfig.json which extends the |
I have the exact same use case as @ChristopherGillis and adding the above worked perfectly for me! Thanks |
We are facing the same issue. Is there any official solution on this? |
Use case description
A change to load tsconfig-paths in supoort of serverless.ts definition files and secondly to optionally pass a different tsconfig file to the serverless command.
Primary use case is to allow the typescript compiler to use different paths when compiling the serverless.ts definition file.
Monorepos such as nx rely heavily on multiple modules referenced via the paths but currently serverless.ts won't be able to utilise them without loading via tsconfig-paths.
By specifying a different tsconfig file (the default is tsconfig.json), specific serverless tsconfig can be used solely for the serverless.ts compilation, allowing separation from the application code and the deployment code.
Proposed solution
require
andproject
- require to implement the tsconfig-paths functionality and project for the tsconfig to use--ts-config-path
as a parameter into serverless, store in config and pass to the parseConfigurationFile function to help with reading the serverless.ts definitionThe text was updated successfully, but these errors were encountered: