Getting "Unexpected token" on deploy for 'export async'

Hey all, I’m a beginner having a strange issue that I’m hoping for some insight on. I’m new to Serverless and node and javascript in general, so excuse my lack of experience.

I’ve been following the tutorial from http://serverless-stack.com and was able to get to the deploy stage and test my deployed functions without problems. I had customized the functions slightly (really just naming more than anything) for my own purposes, but everything worked.

When I got back to it today, I was writing tests (using Chakram). During the course of working on these tests, I upgraded from node 7.10 to 8.0.0. At this point, I’m only modifying test code, the functions themselves are unchanged. I was running into an issue where my test requests were coming back as Unauthorized. So I manually tried it from the command line, same thing. This was working previously and nothing had presumably changed on my AWS deployment. Anyway, at that point I thought, why don’t I try re-deploying and ran ‘serverless deploy’. However, it failed with an Unexpected token error during Webpack compilation.

This is the error I get (replaced long path with ‘blabla’):
ERROR in ./segment/list.js Module parse failed: /blabla/api/node_modules/babel-loader/lib/index.js!/blabla/api/segment/list.js Unexpected token (4:7) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (4:7)

This error occurs for all of my functions and the token in question is ‘async’ in the ‘export async function main’ declaration. What puzzles me is this code was unchanged from when the deploy was working. I thought maybe the upgrade to node 8.0.0 had an effect, so I went back to 7.10, but same issue.

Thoughts?

I think I figured it out. Somehow (I’m still not sure how), my .babelrc file (https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/.babelrc) was missing/deleted. Restoring it solved the issue. I guess this is my punishment for not working out of a git repo from the get-go. It would have been much easier to notice with diffs.

@zkhan Glad you figured it out. Let us know if you run into any issues on our Github page https://github.com/AnomalyInnovations/serverless-stack-com/issues

1 Like

@fanjie All issues thus far are of my own creation. Thank you for the amazing tutorial. I’m really enjoying it.