serverless-webpack icon indicating copy to clipboard operation
serverless-webpack copied to clipboard

Misleading error related to TypeScript configuration

Open lsalazarm99 opened this issue 2 years ago • 1 comments

This is a Bug Report

Description

For bug reports:

  • What went wrong? A misleading error message is being shown when there is an error in the TypeScript configuration file. I think the problem is here. It's assuming any error related to that require is because the dependency is missing. This makes you think you have to install the ts-node package as a dependency and not as a development dependecy (as it should be), but that was not the problem. I had to read the value of the catched error in order to realize that it was a problem with my TypeScript configuration file.
  • What did you expect should have happened? I was expecting a correct error message.
  • What was the config you used? Any incorrect TypeScript configuration is valid to reproduce the error.
  • What stacktrace or error message from your provider did you see?

For feature proposals:

  • What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us.
  • If there is additional config how would it look

Similar or dependent issue(s):

Additional Data

  • Serverless-Webpack Version you're using: 5.7.1
  • Webpack version you're using: 5.73.0
  • Serverless Framework Version you're using: 3.19.0
  • Operating System: 5.15.49-1-MANJARO
  • Stack Trace (if available):

lsalazarm99 avatar Jun 28 '22 07:06 lsalazarm99

@lsalazarm99 I believe you have seen a few incorrect tsconfig.json already, would you mind making a PR for this?

I could imagine starting with something like the following, and then build unit tests around it.

      try {
        require('ts-node/register');
      } catch (e) {
        if (e.code === "MODULE_NOT_FOUND") {
          throw new Error('If you want to use TypeScript with serverless-webpack, please add "ts-node" as dependency.');
        } else {
          throw e;
        }
      }

vicary avatar Jul 03 '22 19:07 vicary