digitalmaas / serverless-plugin-browserifier

Reduce the size and speed up your Node.js based lambda's using browserify.
Other
27 stars 4 forks source link

Any way to use sourcemaps with this plugin? #11

Closed kvarela closed 5 years ago

kvarela commented 5 years ago

I'm having a hard time debugging an issue with my function; any way to get a source map and figure out exactly where the issue is?

fyi here's the error I'm seeing on Lambda:

2018-11-14 16:24:22.407 graphql-api-dev-graphql error module initialization error: TypeError
    at Object.1764.. (/var/task/src/handlers/graphql.js:239273:65)
    at o (/var/task/src/handlers/graphql.js:1:693)
    at /var/task/src/handlers/graphql.js:1:744
    at Object.1761../PointTransaction (/var/task/src/handlers/graphql.js:239051:16)
    at o (/var/task/src/handlers/graphql.js:1:693)
    at /var/task/src/handlers/graphql.js:1:744
    at Object.1759../HotelBooking (/var/task/src/handlers/graphql.js:238935:20)
    at o (/var/task/src/handlers/graphql.js:1:693)
    at /var/task/src/handlers/graphql.js:1:744
    at Object.1750.. (/var/task/src/handlers/graphql.js:238349:28)
nolde commented 5 years ago

Hello!


For debugging, what I usually do is to go into AWS Lambda console and use the code editor there to find the specific lines in the stack trace, so I can verify exactly the same code that is running. It is usually enough to find the issue, and even try some small fixes in place if you have a development environment.

You can also generate the zip file locally by using sls package, then unzipping the file from your .serverless folder. That will also allow you to verify the lines, if you haven't changed the code since.


Anything related to sourcemaps should be configured from within browserify.

With a quick look into https://github.com/browserify/browserify, you can find that adding debug: true to your browserify config should be enough to add inline sourcemaps. Didn't try it though.

That said, AFAIK Node.js does not natively support sourcemaps. Some package like source-map-support should help you to enable it.

Also, if you are transpiling code, you usually have to tap into the transpiling tool to get your sourcemaps. If you are using typescript, you can saerch for articles explaining the specific setup you need.

kvarela commented 5 years ago

Okay, for anyone else with this problem, it was because I used an enum in a TypeORM decorator. Changing the enum to a string fixed this issue.