Skip to content
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

Incompatibility with serverless-plugin-typescript #85

Closed
dsmileym4 opened this issue Dec 12, 2018 · 11 comments
Closed

Incompatibility with serverless-plugin-typescript #85

dsmileym4 opened this issue Dec 12, 2018 · 11 comments

Comments

@dsmileym4
Copy link

Every time I try and package I get:

{ file: undefined,
  start: undefined,
  length: undefined,
  messageText: "File '_warmup/index.ts' not found.",
  category: 1,
  code: 6053,
  reportsUnnecessary: undefined }

  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 (/Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/src/typescript.ts:72:47)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/src/typescript.ts:68:18)
    at Generator.next (<anonymous>)
    at /Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/dist/src/typescript.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/dist/src/typescript.js:3:12)
    at Object.run (/Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/dist/src/typescript.js:62:12)
    at TypeScriptPlugin.<anonymous> (/Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/src/index.ts:132:42)
    at Generator.next (<anonymous>)
    at /Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/dist/src/index.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/dist/src/index.js:3:12)
    at TypeScriptPlugin.compileTs (/Users/dsmiley/workspace/mfour-survey-service/node_modules/serverless-plugin-typescript/dist/src/index.js:103:16)
    at BbPromise.reduce (/Users/dsmiley/nvm/versions/node/v11.4.0/lib/node_modules/serverless/lib/classes/PluginManager.js:391:55)
From previous event:
    at PluginManager.invoke (/Users/dsmiley/nvm/versions/node/v11.4.0/lib/node_modules/serverless/lib/classes/PluginManager.js:391:22)
    at PluginManager.run (/Users/dsmiley/nvm/versions/node/v11.4.0/lib/node_modules/serverless/lib/classes/PluginManager.js:422:17)
    at variables.populateService.then.then (/Users/dsmiley/nvm/versions/node/v11.4.0/lib/node_modules/serverless/lib/Serverless.js:157:33)
    at processImmediate (timers.js:632:19)
    at process.topLevelDomainCallback (domain.js:120:23)
From previous event:
    at Serverless.run (/Users/dsmiley/nvm/versions/node/v11.4.0/lib/node_modules/serverless/lib/Serverless.js:144:8)
    at serverless.init.then (/Users/dsmiley/nvm/versions/node/v11.4.0/lib/node_modules/serverless/bin/serverless:44:28)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           11.4.0
     Serverless Version:     1.34.1

I've spent a day and half combing through your issues and going through step by step guide with no joy. Any help is greatly appreciated:

@juanjoDiaz
Copy link
Owner

The error seems to be related to TypeScript. It can happen if you have an invalid tsconfig.app.json or tsconfig.json or if you have invalid code like a getter without a return.

This might also be caused because serverless-plugin-typescript doesn't support plain js handlers (see serverless/serverless-plugin-typescript#78) and warmup uses a plain js handler.
To fix that you can try to declare serverless-plugin-typescript before serverless-plugin-warmup in your serverless.yaml so serverless-plugin-typescript doesn't try to process the lambda function.

plugins:
  - serverless-plugin-typescript
  - serverless-plugin-warmup

@juanjoDiaz
Copy link
Owner

Any progress on this?
Can the issue be closed?

@robotlemons
Copy link

@juanjoDiaz I am experiencing the same issue and put yml plugins in order you specified but does not work.

@cryptiklemur
Copy link

Same here. Order of plugins does not seem to help

@burkel24
Copy link

burkel24 commented Feb 1, 2019

I am able to use serverless-plugin-typescript without issue:

Here is my tsconfig:

{
  "compilerOptions": {
    "baseUrl": ".",
    "preserveConstEnums": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "target": "es5",
    "outDir": ".build",
    "moduleResolution": "node",
    "lib": ["es2015"],
    "rootDir": "./",
    "paths": {
      "*": ["*", "src/*"]
    }
  }
}

Here is the relevant portion of my serverless.yml:

plugins:
  - serverless-plugin-typescript
  - serverless-plugin-chrome
  - serverless-apigw-binary
  - serverless-apigwy-binary
  - serverless-sentry
  - serverless-plugin-warmup

@dsmileym4
Copy link
Author

Thank you for suggested fixes. I haven't had a chance to revisit this in our code. We implemented a work around which has to be removed to test this. If anyone else can verify this fix works please close this issue. It will be a while before we have any resources to verify.

@juanjoDiaz
Copy link
Owner

I'll close this for now.

It seems clear that the problem is in serverless-plugin-typescript (which seems to be abandoned, so serverless-webpack might be a better option) and there seems to be a workaround.

Feel free to reopen if there is anything else.

@claridgicus
Copy link

@juanjoDiaz sorry to drag this up - Serverless-Plugin-Typescript is under active dev at the moment, can we reopen this?

@juanjoDiaz
Copy link
Owner

Is there anything that we can do here, @claridgicus?

The problem, as stated in serverless/serverless-plugin-typescript#79, is in the typescript plugin, so they just have to fix it. There isn't much that we can do...

Personally, I switched to https://www.npmjs.com/package/serverless-webpack long time ago. 🙂

@dsmileym4
Copy link
Author

I have circled back around to this and verified using serverless-webpack is the way to go. Solved my issues.

@piaverous
Copy link

I have run into this issue in a full typescript setup. serverless/serverless-plugin-typescript#79 was not enough to fix the issue for me, as I have (and need to keep) allowJs: false in my tsconfig.json.

serverless package would then error the following way

{ file: undefined,
  start: undefined,
  length: undefined,
  messageText: 'File \'_warmup/index.js\' has unsupported extension. The only supported extensions are \'.ts\', \'.tsx\', \'.d.ts\'.',
  category: 1,
  code: 6054,
  reportsUnnecessary: undefined }

It would be too costly for me to migrate to serverless-webpack, so I opened this PR to allow for generating the handler function in Typescript directly instead of JS:
#176

It works for me, but was wondering if there was a reason for not doing this?

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

No branches or pull requests

7 participants