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

Can't debug using vscode v1.25, Unable to open 'index.js': File not found #555

Closed
estyh opened this issue Jul 15, 2018 · 16 comments
Closed

Comments

@estyh
Copy link

estyh commented Jul 15, 2018

Description:

I'm trying to debug a lambda with sam cli. It starts up the docker container, and then waits for me to attach a debugger. When I try to attach, vscode pops up a warning:
Unable to open 'index.js': File not found (file:///c:/Users/esty.heller/Documents/Dev/benmanagesoftware/lambda/runtime/node_modules/awslambda/index.js).
And then it just stops and waits, can't do anything except disconnect and let the function run.

Just running the function with sam local invoke works fine.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Windows 10, Docker version 18.03.1-ce, build 9ee9f40 (using linux containers), latest vscode

Output of sam --version:
SAM CLI, version 0.4.0

Optional Debug logs:

$ sam local invoke -e event-create.json -d 5858 CreateUrl
2018-07-15 11:17:47 Invoking create-url.handler (nodejs8.10)
2018-07-15 11:17:47 Found credentials in shared credentials file: ~/.aws/credentials

Fetching lambci/lambda:nodejs8.10 Docker container image......
2018-07-15 11:17:49 Mounting C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener as /var/task:ro inside runtime container
Debugger listening on ws://0.0.0.0:5858/3e08373e-2480-470f-9eed-d7fe2651cae0
For help see https://nodejs.org/en/docs/inspector
Debugger attached.

At this point, I try to attach using my launch config:

{
			"name": "Attach to Sam Local",
			"type": "node",
			"request": "attach",
			"port": 5858,
			"protocol": "inspector",
			"address": "localhost",
			"localRoot": "${workspaceRoot}/",
			"remoteRoot": "/var/task/"
		}

And I get a popup warning Unable to open 'index.js': File not found (file:///c:/Users/esty.heller/Documents/Dev/benmanagesoftware/lambda/runtime/node_modules/awslambda/index.js). and it won't attach.

Here is my template.yaml

AWSTemplateFormatVersion: '2010-09-09' 
Transform: AWS::Serverless-2016-10-31  
 
Globals: 
  Function: 
    Timeout: 300 
    Runtime: nodejs8.10  
    MemorySize: 512 
    
Resources: 
  CreateUrl: 
    Type: AWS::Serverless::Function 
    Properties: 
      Handler: create-url.handler 
      Role: arn:aws:iam::933503113720:role/benmanage-lambda-api-dev
      FunctionName: url-shortener-create-url-dev

Here is the create-url.js

exports.handler = async event => {
	console.log(JSON.stringify(process.env, null, '\t'));
	return event;
};

and here is event-create.json

{
	"url": "https://hashids.org",
	"metaData": {
		"email": "test@example.com",
		"phone": "+13145291389"
	}
}

Add --debug flag to command you are running

$ sam local invoke -e event-create.json -d 5858 CreateUrl --debug
2018-07-15 11:40:49 local invoke command is called
2018-07-15 11:40:49 1 resources found in the template
2018-07-15 11:40:49 Found Serverless function with name='CreateUrl' and CodeUri='.'
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 http://localhost:None "GET /v1.35/_ping HTTP/1.1" 200 2
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Found one Lambda function with name 'CreateUrl'
2018-07-15 11:40:49 Invoking create-url.handler (nodejs8.10)
2018-07-15 11:40:49 Environment variables overrides data is standard format
2018-07-15 11:40:49 Loading AWS credentials from session with profile 'None'
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable config_file from defaults.
2018-07-15 11:40:49 Loading variable credentials_file from defaults.
2018-07-15 11:40:49 Loading variable data_path from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable credentials_file from defaults.
2018-07-15 11:40:49 Loading variable config_file from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable metadata_service_timeout from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable metadata_service_num_attempts from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Looking for credentials via: env
2018-07-15 11:40:49 Looking for credentials via: assume-role
2018-07-15 11:40:49 Looking for credentials via: shared-credentials-file
2018-07-15 11:40:49 Found credentials in shared credentials file: ~/.aws/credentials
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable region from config file with value 'us-east-1'.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable region from config file with value 'us-east-1'.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable region from config file with value 'us-east-1'.
2018-07-15 11:40:49 Resolving code path. Cwd=C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener, CodeUri=.
2018-07-15 11:40:49 Resolved absolute path to code is C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener
2018-07-15 11:40:49 Code C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener is not a zip/jar file
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 http://localhost:None "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None
2018-07-15 11:40:49 Looking for auth config
2018-07-15 11:40:49 No auth config in memory - loading from filesystem
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Looking for auth entry for 'docker.io'
2018-07-15 11:40:49 No entry found
2018-07-15 11:40:49 No auth config found
2018-07-15 11:40:52 http://localhost:None "POST /v1.35/images/create?tag=nodejs8.10&fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:nodejs8.10 Docker container image......
2018-07-15 11:40:52 Mounting C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener as /var/task:ro inside runtime container
2018-07-15 11:40:52 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 90
2018-07-15 11:40:52 http://localhost:None "GET /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/json HTTP/1.1" 200 None
2018-07-15 11:40:52 http://localhost:None "GET /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/json HTTP/1.1" 200 None
2018-07-15 11:40:52 http://localhost:None "POST /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/start HTTP/1.1" 204 0
2018-07-15 11:40:52 Setting up SIGTERM interrupt handler
2018-07-15 11:40:52 http://localhost:None "GET /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/json HTTP/1.1" 200 None
2018-07-15 11:40:52 http://localhost:None "POST /containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/attach?stream=1&stdin=0&logs=1&stderr=1&stdout=1 HTTP/1.1" 101 0
Debugger listening on ws://0.0.0.0:5858/0d8e8c68-dc15-4b74-b038-e0b83ca1cf1c
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
@chrba
Copy link

chrba commented Jul 15, 2018

I have the same problem using the latest version of vscode.

Linux Ubuntu
SAM CLI 0.4.0
vscode 1.25.1
nodejs 8.10.

@dalexander-trc
Copy link

dalexander-trc commented Jul 16, 2018

I'm also experiencing this problem as of this morning.

Windows 10
Docker 18.03.1-ce build 93354b3
SAM CLI 0.2.8
VSCode 1.25.1
NodeJS 6.10

@jfuss
Copy link
Contributor

jfuss commented Jul 17, 2018

Is this only with the latest version of VSCode? Did this work in the previous 1.24 version?

Trying to narrow down the search field here but the comments suggest something in 1.25 changed.

@chrba
Copy link

chrba commented Jul 17, 2018

yes, it is working in the previous version 1.24 so the problem only occurs in the latest version of VSCode.

@jfuss
Copy link
Contributor

jfuss commented Jul 17, 2018

So my recommendation is to stay a version behind (if you can) until we can track what VSCode did to break the CLI.

@jfuss jfuss changed the title Can't debug using vscode windows 10, Unable to open 'index.js': File not found Can't debug using vscode v1.25, Unable to open 'index.js': File not found Jul 17, 2018
@alexcasalboni
Copy link
Contributor

Same problem here on MacOS Sierra with 1.25.1.

@alexcasalboni
Copy link
Contributor

Something similar happens for Node.js 6.10, but instead of failing it lets you debug a remote index.js file that looks pretty similar to this gist.

@bingtimren
Copy link

I don't know if my observation is related to this issue but here is it anyway:
=============== VS Code ===============
Version: 1.25.1
Commit: 1dfc5e557209371715f655691b1235b6b26a06be
Date: 2018-07-11T15:40:20.190Z
Electron: 1.7.12
Chrome: 58.0.3029.110
Node.js: 7.9.0
V8: 5.8.283.38
Architecture: x64
================== SAM CLI ======================
SAM CLI, version 0.5.0
================== OS ==========================
Linux bingstp 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
=================== Observation =====================
I am working on an example project, and found if I just change the lambda runtime to nodejs8.10, the problem appears with message "Unable to open 'index.js': File not found (file:///home/bing/git/aws-serverless-roundtrip-option1/sam-app/runtime/node_modules/awslambda/index.js).", but if I change runtime to "nodejs6.10" there's no such problem.

@bingtimren
Copy link

bingtimren commented Aug 1, 2018

I also would like to add a walk-around. If, in launch.json, both "localRoot" and "remoteRoot" is properly set, especially "localRoot" is set as the root of the source, corresponding to the "codeUri" property in template, you can just set a breakpoint in the code, ignore the error message (although a bit of annoying to see it there) and press F5 or click the Continue (play) button, and execution will pause at the breakpoint and you can trace your code. It's just you cannot trace what's inside the code from that "awslambda/index.js".

For example, in the example project I'm working on, "CodeUri: src/" is in "template.yaml" in the properties of the lambda function, and "localRoot": "${workspaceRoot}/src" is in the launch.json to match the codeUri.

Or, if breakpoint does not work, you can still use the "debugger" statement to break the execution.

@seraphjiang
Copy link

@bingtimren workaround works for me

  1. need to change the localRoot per your CodeUri. in my case it is codeURI: ../../
  2. better to use debugger to break

another workaround is use
chrome://inspect to attach and debug

@Jeremias-Tecnom
Copy link

I have upgraded to v1.26 and still same issue

@drycode
Copy link

drycode commented Oct 3, 2018

I'm having this same problem with v.1.27

@sriram-mv
Copy link
Contributor

{
    "version": "0.6.0",
    "configurations": [
        {
            "name": "Attach to SAM CLI",
            "type": "node",
            "request": "attach",
            "address": "localhost",
            "port": 5859,
            "localRoot": "${workspaceRoot}",
            "sourceMapPathOverrides": {
                "${workspaceRoot}/runtime": "${remoteRoot}",
            },
            "remoteRoot": "/var/task",
            "protocol": "inspector",
            "stopOnEntry": false
        }
    ]
}

This was the setting, under which I was able to get it to work. VScode needs to be open at the sam-app level. I'll have a PR out for this soon.

@sanathkr
Copy link
Contributor

We have updated the documentation to reflect the correct mechanism to launch vscode debugging.

@seraphjiang
Copy link

We have updated the documentation to reflect the correct mechanism to launch vscode debugging.

could you provide updated document link?

@jfuss
Copy link
Contributor

jfuss commented Oct 12, 2018

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