serverless-plugin-typescript
serverless-plugin-typescript copied to clipboard
serverless-plugin-typescript not working with serverless-compose
There are 2 issues when using serverless-plugin-typescript in combination with serverless compose:
For context, this is my folder structure: /api handler.ts serverless.yml package.json serverless-compose.yml
I have taken it from this minimal repo setup, have removed the react app, and have added typescirpt - https://github.com/serverless/compose-website-example
serverless-compose.yml
services:
demo-api:
path: api
package.json
{
"dependencies": {
"@serverless-components/website": "^0.1.0",
"@serverless/compose": "^1.2"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.101",
"serverless-offline": "^8.8.0",
"serverless-plugin-optimize": "^4.2.1-rc.1",
"serverless-plugin-typescript": "^2.1.2"
}
}
/api/handler.ts
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'success' }),
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
}
};
/api/serverless.yml
service: demo-api
frameworkVersion: "3"
plugins:
- serverless-plugin-typescript
- serverless-offline
provider:
name: aws
runtime: nodejs16.x
functions:
hello:
handler: handler.handler
events:
- httpApi:
method: GET
path: /api/hello
- Running
sls api:offlinefor the second time exits with the error below. The first execution is succeeding, as it generates the .build folder within /api.
Compiling with Typescript...
Typescript compiled.
Environment: darwin, node 16.13.1, framework 3.19.0 (local), plugin 6.2.2, SDK 4.3.2
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Error: EEXIST: file already exists, symlink '/***/compose-website-example/fullstack-app/api/node_modules' -> '/***/compose-website-example/fullstack-app/api/.build/node_modules'
Error:
- Running
sls deployis also failing because it is expecting the node_modules folder at the wrong place
Deploying to stage dev
demo-api › waiting
demo-api › deploying
demo-api › Running "serverless deploy --stage dev"
demo-api › Deploying demo-api to stage dev (us-east-1)
demo-api › Compiling with Typescript...
demo-api › Typescript compiled.
demo-api › × Stack demo-api-dev failed to deploy (1s)
demo-api › Environment: darwin, node 16.13.1, framework 3.19.0 (local), plugin 6.2.2, SDK 4.3.2
demo-api › Credentials: Local, "default" profile
demo-api › Docs: docs.serverless.com
demo-api › Support: forum.serverless.com
demo-api › Bugs: github.com/serverless/serverless/issues
demo-api › Error:
demo-api › Error: ENOENT: no such file or directory, stat '/***/compose-website-example/fullstack-app/api/node_modules'
Both sls offline and sls deploy are working fine if I take the serverless-plugin-typescript out