aws-toolkit-jetbrains
aws-toolkit-jetbrains copied to clipboard
NodejsNpmBuilder:Resolver does not find node or npm runtime, although SAM does
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
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
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
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
I had a similar problem with VS Code, I overcame the issue doing the following:
- set NVM default alias to use Node 14 (14.9.0 in my case):
nvm alias default 14 - copied the previous configurations in the launch.json (specific to VS Code) and deleted the file
- created from scratch creating the launch.json file
- paste the configuration I had before
for me it worked
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
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
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 "$@"
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
It really works! thanks bro! @xinaxu