Serverless plugin for zero-config Typescript support
Original NPM Module: http://www.npmjs.com/package/serverless-plugin-typescript
This version of
serverless-typescript-plugin fixes symbolic link issues with Windows OS resulting in the following errors:
- EPERM: operation not permitted, scandir...
- EPERM: operation not permitted, symlink...
When attaching the "node_modules" folder to the build
Created PR for original plugin: http://www.github.com/prismagraphql/serverless-plugin-typescript/pull/103
- Zero-config: Works out of the box without the need to install any other compiler or plugins
- Supports ES2015 syntax + features (
sls deploy function
sls invoke local+
- Integrates nicely with
yarn add --dev @hewmen/serverless-plugin-typescript
npm install --save-dev @hewmen/serverless-plugin-typescript
Add the following plugin to your
See example folder for a minimal example.
tsconfig.json file used by the plugin looks like this:
Note 1: The
rootDiroptions cannot be overwritten.
Note 2: Don't confuse the
tsconfig.jsonin this repository with the one mentioned above.
Including extra files
All files from
package/include will be included in the final build file. See Exclude/Include
Google Cloud Functions
When using with Google Cloud Functions via the serverless-google-cloudfunctions
plugin, you simply have to provide a
main field in your
// ..."main": "handler.js"// ..
And this plugin will automatically compile your typescript correctly. Note
that the field must refer to the compiled file name, namely, ending with a
main field was not found, then this plugin will use
compilation begins, it will check to see that the file indicated exists with a
.ts extension before actually trying to compile it.
The normal Serverless deploy procedure will automatically compile with Typescript:
- Create the Serverless project with
serverless create -t aws-nodejs
- Install Serverless Typescript as above
- Deploy with
Usage with serverless-offline
The plugin integrates very well with serverless-offline to simulate AWS Lambda and AWS API Gateway locally.
Add the plugins to your
serverless.yml file and make sure that
serverless-offline as the order is important:
plugins:...- '@hewmen/serverless-plugin-typescript'...- serverless-offline...
serverless offline or
serverless offline start to start the Lambda/API simulation.
In comparison to
serverless offline, the
start command will fire an
init and a
end lifecycle hook which is needed for
serverless-offline and e.g.
serverless-dynamodb-local to switch off resources (see below)
Configure your service the same as mentioned above, but additionally add the
plugin as follows:
plugins:- '@hewmen/serverless-plugin-typescript'- serverless-dynamodb-local- serverless-offline
serverless offline start.
Other useful options
You can reduce the clutter generated by
disable timeouts with
Run a function locally
To run your compiled functions locally you can:
$ serverless invoke local --
-f(required) is the name of the function to run
--watch- recompile and run a function locally on source changes
-p(optional) path to JSON or YAML file holding input data
-d(optional) input data
You can easily enable support for source-maps (making stacktraces easier to read) by installing and using the following plugin:
yarn add --dev source-map-support
// inside of your function
If you are using webpack (most likely). Add
devtool: 'source-map' to
moduleexports =... snip ...devtool: 'source-map'... snip ...
Join our Slack community if you run into issues or have questions. We love talking to you!