Skip to content

Is this plugin compatible when using multiple runtimes? #43

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

Open
riltsken opened this issue Oct 24, 2017 · 12 comments
Open

Is this plugin compatible when using multiple runtimes? #43

riltsken opened this issue Oct 24, 2017 · 12 comments

Comments

@riltsken
Copy link

riltsken commented Oct 24, 2017

Heya. First off just wanted to say this plugin made my life a whole lot easier by not dealing with compilation configuration :)

The current issue I am running into is that I wanted to add a python lambda alongside my typescript lambdas. Regardless of my tsconfig / serverless.yml I can't seem to prevent serverless-plugin-typescript from trying to compile my python functions.

If you think this is NOT an issue with serverless-plugin-typescript I am happy to investigate more, but my current understanding is that this seems to be the culprit since I don't expect it to be jumping into my non-typescript folders.

If you think this is an issue that is easily fixable I am happy to dive in, but I just wanted to make sure I wasn't missing something and any direction you might provide before I do so.

My current layout is the following

root
 \_funcs
   \_geocode
   \_queue
 \_funcs_python
   \_logentries
 \_serverless.yml
 \_tsconfig.json

tsconfig

    "compilerOptions": {
        "allowSyntheticDefaultImports": false,
        "alwaysStrict": true,
        "allowJs": true,
        "declaration": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noImplicitAny": false,
        "noUnusedLocals": true,
        "suppressImplicitAnyIndexErrors": false,
        "outDir": ".build",
        "rootDir": "./",
        "target": "es5",
        "lib": ["es2015"],
        "sourceMap": true,
        "alwaysStrict": true
    },
    "include": ["funcs/**/*.ts"],
    "compileOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    },
    "exclude": [
        "dist"
    ]

serverless.yml (couple things omitted for privacy

service: mapping
frameworkVersion: "=1.22.0"
stage: dev

provider:
  name: aws
  runtime: nodejs6.10
  memorySize: 128
  timeout: 5

package:
  excludeDevDependencies: true
  include:
    - node_modules/**/*
    - funcs/**/*.ts

functions:
  geocode:
    name: ${self:service}-geocode
    handler: funcs/geocode/index.main
  queue:
    name: ${self:service}-queue
    handler: funcs/queue/index.main
  logentries:
    name: ${self:service}-logentries
    handler: funcs_python/logentries/main.lambda_handler
    runtime: python2.7

plugins:
  - serverless-plugin-typescript
  - serverless-prune-plugin

custom:
  prune:
    automatic: true
    number: 5

Error

$ SLS_DEBUG=* . ./settings.staging.sh && serverless deploy -s staging
Serverless: Load command run
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command emit
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command prune
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
{ file: undefined,
  start: undefined,
  length: undefined,
  messageText: 'File \'funcs_python/logentries/main.ts\' not found.',
  category: 1,
  code: 6053 }
 
  Type Error ---------------------------------------------
 
  Cannot read property 'getLineAndCharacterOfPosition' of undefined
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Stack Trace --------------------------------------------
 
TypeError: Cannot read property 'getLineAndCharacterOfPosition' of undefined
    at allDiagnostics.forEach.diagnostic (/home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/typescript.js:71:56)
    at Array.forEach (native)
    at Object.<anonymous> (/home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/typescript.js:67:24)
    at Generator.next (<anonymous>)
    at /home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/typescript.js:7:71
    at __awaiter (/home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/typescript.js:3:12)
    at Object.run (/home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/typescript.js:62:12)
    at TypeScriptPlugin.<anonymous> (/home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/index.js:110:50)
    at Generator.next (<anonymous>)
    at /home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/index.js:7:71
    at __awaiter (/home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/index.js:3:12)
    at TypeScriptPlugin.compileTs (/home/storiel/work/mapping/lambda/node_modules/serverless-plugin-typescript/dist/src/index.js:99:16)
    at BbPromise.reduce (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:358:55)
From previous event:
    at PluginManager.invoke (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:358:22)
    at PluginManager.spawn (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:376:17)
    at Deploy.BbPromise.bind.then.then (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:117:50)
From previous event:
    at Object.before:deploy:deploy [as hook] (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:107:10)
    at BbPromise.reduce (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:358:55)
From previous event:
    at PluginManager.invoke (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:358:22)
    at PluginManager.run (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/classes/PluginManager.js:389:17)
    at variables.populateService.then (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/Serverless.js:99:33)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
    at Serverless.run (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/lib/Serverless.js:86:74)
    at serverless.init.then (/home/storiel/.nvm/versions/node/v7.10.1/lib/node_modules/serverless/bin/serverless:39:50)
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless
 
  Your Environment Information -----------------------------
     OS:                     linux
     Node Version:           7.10.1
     Serverless Version:     1.22.0
 
error Command failed with exit code 1.
@jhaals
Copy link

jhaals commented Feb 8, 2018

stumbled into the same issue when trying to use two runtimes, any updates or solutions/workarounds?

@riltsken
Copy link
Author

riltsken commented Feb 8, 2018

I did not solve this issue or find a workaround. At some point I was planning on compiling manually to avoid this issue, but just haven't had a big need to do it. Still think this lib is the bees knees if not using multiple runtimes :)

@liam-betsworth
Copy link

Also ran into the same issue. Exclude doesn't seem to do anything.

@ACollectionOfAtoms
Copy link

ACollectionOfAtoms commented May 22, 2019

Running into the same issue! I think this issue prevents usage of: https://github.com/svdgraaf/serverless-basic-authentication as it requires some python

divyenduz pushed a commit to divyenduz/languagelearners that referenced this issue Jul 13, 2019
@Jordan-Eckowitz
Copy link

Same issue here. When trying to run serverless-offline it crashes for python lambda functions as its looking for .js or .ts file extensions.

@bobzoller
Copy link

super ugly hack, but just because there is no workaround listed here yet...

patch dist/src/index.js with this:

--- index.js.orig       2021-01-18 10:54:23.000000000 -1000
+++ index.js.new        2021-01-18 10:54:57.000000000 -1000
@@ -81,7 +81,7 @@
                 [options.function]: service.functions[this.options.function]
             };
         }
-        return service.functions;
+        return Object.keys(service.functions).reduce(function (memo, k) { if (service.functions[k].typescript !== false) memo[k] = service.functions[k]; }, {});
     }
     get rootFileNames() {
         return typescript.extractFileNames(this.originalServicePath, this.serverless.service.provider.name, this.functions);

and then add typescript: false to any function that isn't Typescript. (you'll see a warning about an unknown property)

@serp-ya
Copy link

serp-ya commented Aug 6, 2021

@bobzoller thanks a lot for the hack! Thanks to your comment I found how to avoid this problem without any changes of the node_modules files.

TS compiling successfully done if I creates a same name .ts file near the Python handler.

It means, I have a function config in the serverles.yml:

functions:
  prepare-data:
    name: prepare-data
    handler: functions/prepare-data/src/handler.convert_data
    runtime: python3.6

And two files

Python:

# functions/prepare-data/src/handler.py
def convert_data(event, context):
    print('Hello Python!!1')

    return 0

TS:

// functions/prepare-data/src/handler.ts
// empty file

And it helps to avoid the compilation failture

@Cittadini
Copy link

Cittadini commented Aug 26, 2021

Hi @serp-ya and @bobzoller , with your hack TS compiling successfully, but lambda contains only js file.
Is there a setting for maintain the py file?

Thanks,
Andrea

@serp-ya
Copy link

serp-ya commented Aug 27, 2021

@Cittadini I'm not sure why it happened on your side but my lambda works fine with python code... Above I shown a my Lambda configs and it contains important line runtime: python3.6 and I have a global config provider.runtime: nodejs12.x in `serverless.yml too.

I hope it will helps you.

P.S. And not forget to describe what is a function will need to use for a Lambda deploy. I use a converter_data here =>handler: functions/prepare-data/src/handler.convert_data

@Cittadini
Copy link

Hi @serp-ya thanks for your tips.
I have a config like yours.
Maybe I have a plugin that remove the py files: I hope to find it!

Thanks,
Andrea

@vectorjohn
Copy link

This is fixed now in master, fixed by PR #277

@ScopeSV
Copy link

ScopeSV commented Oct 18, 2022

I ran into the error Error: Typescript compilation failed. Please ensure handlers exists with ext .ts or .js when trying to use both JS/TS and Go handlers.

I was using v2.1.2
Upgrading to v2.1.4 solved it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants