aws-toolkit-jetbrains icon indicating copy to clipboard operation
aws-toolkit-jetbrains copied to clipboard

NodejsNpmBuilder:Resolver does not find node or npm runtime, although SAM does

Open chillbirdo opened this issue 3 years ago • 5 comments
trafficstars

Describe the bug

although sam build works fine, when trying to run the lambda function through the plugin, it fails. Clicking on the Lambda symbol next to the function definition in IntelliJ, I am getting the following output:

docker ps
/usr/local/bin/sam build Function --template /home/chillbirdo/path/to/aws-lambda-project/.aws-sam/temp-template.yaml --build-dir /home/chillbirdo/path/to/aws-lambda-project/.aws-sam/build
Building codeuri: /home/chillbirdo/path/to/aws-lambda-project/create-design runtime: nodejs14.x metadata: {} architecture: x86_64 functions: ['Function']

Build Failed
Error: NodejsNpmBuilder:Resolver - Path resolution for runtime: nodejs14.x of binary: npm was not successful
SAM Build has failed: Command did not exit successfully, exit code: 1
3 has failed: Command did not exit successfully, exit code: 1

oddly enough, executing the exact same line from the output in the terminal works fine: /usr/local/bin/sam build Function --template /home/chillbirdo/path/to/aws-lambda-project/.aws-sam/temp-template.yaml --build-dir /home/chillbirdo/path/to/aws-lambda-project/.aws-sam/build

I have set both nodejs14 and npm in my PATH environment variable. Excerpt:

/home/chillbirdo/.nvm/versions/node/v14.19.0/bin/node:/home/chillbirdo/.nvm/versions/node/v14.19.0/bin/npm

Furthermore in my IJ settings, I have configured my nodejs14 as well as npm runtime (see screenshot attached).

To Reproduce Versions: IntelliJ: IntelliJ IDEA 2021.3 (Ultimate Edition), Build #IU-213.5744.223, built on November 27, 2021 AWS Toolkit Plugin: 1.37-213 SAM: SAM CLI, version 1.37.0 nodejs: v14.19.0 npm: 6.14.16

sam init, choose all standard options, but node14 and zip packaging. Open with IJ. Try to start the Hello World Lambda via the plugin.

Expected behavior

Since sam build works, I would expect the plugin to be able to do the same and invoke it. I also configured the "node" configs in the IJ settings, didn't help

Screenshots

image image As you can see there is an error in the config, the Exception-Log is attached there: intellij-aws-plugin-ClassCastException.txt The Exception only occurs when trying to change a value, see #3064

Desktop (please complete the following information):

  • OS: Linux Mint
  • IntelliJ: IntelliJ IDEA 2021.3 (Ultimate Edition), Build #IU-213.5744.223, built on November 27, 2021
  • AWS Toolkit Plugin: 1.37-213
  • SAM: SAM CLI, version 1.37.0
  • nodejs: v14.19.0
  • npm: 6.14.16

chillbirdo avatar Feb 10 '22 19:02 chillbirdo

Thanks for the detailed write-up! Root cause is that we don't let the IDE pass along the existing environment and so SAM CLI can't find node.js

https://github.com/aws/aws-toolkit-jetbrains/blob/0d0c28bd30c1911d78688e3d86cfc23c7cbe626d/jetbrains-core/src/software/aws/toolkits/jetbrains/core/executables/ExecutableCommon.kt#L44

rli avatar Feb 15 '22 17:02 rli

Thanks @rli for the reply and for digging into the code! Running and debugging Lambda functions locally is one of the main features of the aws-toolkit. This bug makes it impossible to do so, or am I missing something? Shouldn't that bug be highly priorized? BR

chillbirdo avatar Feb 17 '22 18:02 chillbirdo

I had a similar problem with VS Code, I overcame the issue doing the following:

  1. set NVM default alias to use Node 14 (14.9.0 in my case): nvm alias default 14
  2. copied the previous configurations in the launch.json (specific to VS Code) and deleted the file
  3. created from scratch creating the launch.json file
  4. paste the configuration I had before

for me it worked

lucamezzalira avatar Jul 04 '22 22:07 lucamezzalira

I ended up doing below for Jetbrain

cd /usr/local/bin
mv sam sam.old
vim sam
## Content:
## #!/bin/bash
## PATH="....." /usr/local/aws-sam-cli/current/bin/sam "$@"
chmod +x sam

xinaxu avatar Aug 30 '22 06:08 xinaxu

cd /usr/local/bin mv sam sam.old vim sam

@xinaxu what is the actual content of your sam file? I dont know what to replace "...." in PATH

letuss004 avatar Sep 15 '22 16:09 letuss004

cd /usr/local/bin
mv sam sam.old
vim sam

See the content of the bash script below. Sourcing nvm brings the node environment to the PATH. Also you can upgrade safely.

#!/bin/bash
. ~/.nvm/nvm.sh
/usr/local/bin/sam.old "$@"

mete89 avatar Mar 24 '23 19:03 mete89

To summarize

cd /usr/local/bin mv sam sam.old sudo nano sam

paste:

#!/bin/bash
. ~/.nvm/nvm.sh
/usr/local/bin/sam.old "$@"

chmod +x sam

alexndr-n avatar Jun 05 '23 15:06 alexndr-n

It really works! thanks bro! @xinaxu

sudowanderer avatar Aug 10 '23 06:08 sudowanderer