Amplify-cli: If you publish a lambda using a local npm package, amplify-cli becomes unusable

Created on 20 Mar 2019  路  3Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
I made a mistake today and published a lambda referencing a local package:

"dependencies": {
    "aws-sdk": "^2.413.0",
    "axios": "^0.18.0",
    "my-local-package": "file:~/src/my-local-package",
}

Of course, the lambda doesn't execute properly (very much expected, and very much my fault). However, my local amplify-cli has now become completely unusable. Almost every command (even amplify status) results in the following error:

error: uncaughtException: ENOENT: no such file or directory, stat '/Users/zach/src/project-name/amplify/.temp/#current-cloud-backend/function/function-name/src/node_modules/my-local-package'

The following did not solve this problem:

  1. Deleted the lambda function
  2. Deleted the stack associated with the lambda function

Furthermore, anyone who checks out my env will also have their local amplify-cli end up in a permanently broken state.

To Reproduce
Steps to reproduce the behavior:
Follow the steps outlined in the description.

Expected behavior
I think there's two pieces of unexpected behaviour here:

  1. If possible, it would be great if amplify-cli refused to publish lambdas that referenced local node packages (very difficult, I realize)
  2. More practically, amplify-cli shouldn't blow up when a node package is missing in the cloud.

Desktop (please complete the following information):

  • OS: macOS High Sierra 10.13.6
  • Version 1.1.6
bug functions

Most helpful comment

What is the recommended way to use locally created npm packages? npm link doesn't work because the zip file for the lambda doesn't follow the symlinks created by npm link.

All 3 comments

Okay, so I've found a terrible, awful solution to this problem:

  1. Download #current-cloud-backend.zip from the deployment (not the hosting) bucket
  2. Extract the zip, navigate to function/function-name/src/node_modules and replace the my-local-package shortcut with an empty folder
  3. Package your changes and upload them to the deployment bucket, overwriting the old #current-cloud-backend.zip

@zjullion thank you for reporting this. I have updated the code not to include any content from functions node_modules when backing up the current_cloud_backend. This will help for new pushes, but won't be able to fix it for already pushed backend.

What is the recommended way to use locally created npm packages? npm link doesn't work because the zip file for the lambda doesn't follow the symlinks created by npm link.

Was this page helpful?
0 / 5 - 0 ratings