OfficeDev / TeamsFx

Developer tools for building Teams apps
Other
427 stars 165 forks source link

Teams Toolkit cannot find node.js but node.js is configured in PATH #9051

Closed 9pr19 closed 10 months ago

9pr19 commented 11 months ago

Describe the bug I get the «(×) Error: Node.js Cannot find Node.js.» but node is actually on my computer and in the PATH.

To Reproduce

With a fresh PowerShell console I can start node by typing the node command. I get the same error if I start VSCode from the powershell console.

Expected behavior Find the node from PATH.

Screenshots NA

VS Code Extension Information (please complete the following information):

ghost commented 11 months ago

Thank you for contacting us! Any issue or feedback from you is quite important to us. We will do our best to fully respond to your issue as soon as possible. Sometimes additional investigations may be needed, we will usually get back to you within 2 days by adding comments to this issue. Please stay tuned.

swatDong commented 11 months ago

@9pr19 , which node version are you using? Teams Toolkit runs node -version to check the version.

Or, you could skip the node check step via commenting out it from .vscode/tasks.json file.

    ...
        {
            "label": "Validate prerequisites",
            "type": "teamsfx",
            "command": "debug-check-prerequisites",
            "args": {
                "prerequisites": [
                    // "nodejs", // remove this or comment it out
                    "m365Account",
                    "portOccupancy"
                ],
                "portOccupancy": [
                    3978,
                    9239
                ]
            }
        },
    ...
9pr19 commented 11 months ago

Hello @swatDong thank you for your help

PS C:\Users\me> node --version
v18.16.0

I’m a total beginner with VSCode and Teams toolkit. Commenting out the nodejs task enable to deploy more and less successfully (I do not really (still have to understand the whole mechanism).

But I still get that weird message :

'"node"' is not recognized as an internal or external command,
operable program or batch file.

Regards

swatDong commented 11 months ago

Hello @swatDong thank you for your help

PS C:\Users\me> node --version
v18.16.0

I’m a total beginner with VSCode and Teams toolkit. Commenting out the nodejs task enable to deploy more and less successfully (I do not really (still have to understand the whole mechanism).

But I still get that weird message :

'"node"' is not recognized as an internal or external command,
operable program or batch file.

Regards

This error looks like your node only works in PowerShell but not in VSCode or other command window.

Could you please try node --version in:

Do they work well?

9pr19 commented 11 months ago

@swatDong

image

swatDong commented 11 months ago

Then where did you get the error '"node"' is not recognized as an internal or external command, ...?

Does node also work in the Command Prompt (not PowerShell)? The error does look like from Command Prompt (the system default shell used in Teams Toolkit):

image
9pr19 commented 11 months ago

@swatDong

Good point - in a standard command prompt it’s not working: image

And also in the standard command prompt in VSCode (I just learned how to switch from to a different terminal):

image

The nodejs path is in my user PATH and not in the system PATH - this might be the source of the problem .

I get the message at the end of the run process (I still do not understand the meaning of this part - it keeps waiting for ...): image

9pr19 commented 11 months ago

@swatDong

As you can see, in the standard command prompt the nodejs path is in the path:

C:\Users\<ME>>echo %path%
C:\Program Files\OpenSSH\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\TortoiseGit\bin;C:\Users\admin.local\AppData\Local\Microsoft\WindowsApps;C:\Program Files\dotnet\;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Oracle\VirtualBox;;C:\Program Files\Oracle\VirtualBox;;C:\Program Files\Oracle\VirtualBox";C:\Users\<ME>\AppData\Local\Microsoft\WindowsApps;C:\Users\<ME>\AppData\Local\Programs\Git\cmd;C:\Users\<ME>\go\bin;C:\Users\<ME>\Application\pbi-tools;C:\Users\<ME>\.dotnet\tools;**C:\Users\<ME>\Application\node-v18.16.0-win-x64**;;C:\Users\<ME>\AppData\Local\Programs\Microsoft VS Code\bin

C:\Users\<ME>>node
'node' is not recognized as an internal or external command,
operable program or batch file.

The directory exists and contains nodejs:

C:\Users\<ME>>cd C:\Users\<ME>\Application\node-v18.16.0-win-x64

C:\Users\<ME>\Application\node-v18.16.0-win-x64>dir
 Volume in drive C has no label.
 Volume Serial Number is E67A-67A7

 Directory of C:\Users\<ME>\Application\node-v18.16.0-win-x64

12/06/2023  13:58    <DIR>          .
12/06/2023  13:58    <DIR>          ..
12/04/2023  05:45            55 459 CHANGELOG.md
23/09/2022  04:40               334 corepack
23/09/2022  04:40               218 corepack.cmd
16/02/2023  17:40             3 033 install_tools.bat
29/03/2023  08:01           117 112 LICENSE
12/04/2023  06:04        69 938 296 node.exe
14/10/2021  02:30               702 nodevars.bat
12/04/2023  05:45            10 630 node_etw_provider.man
12/04/2023  06:04    <DIR>          node_modules
16/02/2023  17:40             1 365 npm
16/02/2023  17:40               483 npm.cmd
16/02/2023  17:40             1 567 npx
16/02/2023  17:40               539 npx.cmd
12/04/2023  05:45            37 308 README.md
              13 File(s)     70 167 046 bytes
               3 Dir(s)  764 232 785 920 bytes free

C:\Users\<me>\Application\node-v18.16.0-win-x64>node
Welcome to Node.js v18.16.0.
Type ".help" for more information.
>
swatDong commented 11 months ago

Is the asterisk (*) expected in %path% or just for text highlight?

I'm not sure what's wrong with the command prompt but may try this to verify:

c:\>set path="C:\Users\<me>\Application\node-v18.16.0-win-x64"

c:\>echo %path%
"C:\Users\<me>\Application\node-v18.16.0-win-x64"

c:\>node
9pr19 commented 11 months ago

@swatDong Very strange - something is definitely wrong with my path variable:

C:\Users\<ME>>node
'node' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\<ME>>set path="%path%"

C:\Users\<ME>>node
Welcome to Node.js v18.16.0.
Type ".help" for more information.
>
swatDong commented 10 months ago

@9pr19 , I just found one possible way to repro this - set extra semicolon(;) and double-quote(") in PATH.

My node is installed at c:/program files/nodejs. And if I set env like this:

image

In PowerShell, it works:

image

But in CMD, it's similar to you:

image

So could you check if there's any extra character (especially ; and " ) in your path?

9pr19 commented 10 months ago

@swatDong ,

You are really good.

After cleaning a few semicolons in system path it now works like a charm. The double semicolons ;; where due to directory which does not exists on the system are converted to an empty string. path=C:\Windows;C:\dontexists;C:\ is converted to path=C:\Windows;;C:\.

Thank you very much for your help.

synth commented 8 months ago

I am experiencing this, although I am on OSX. I have node available in my regular terminal and in VS code terminal but when I try to debug in VS Code with teams toolkit, I get Cannot find Node.js :(

If I remove the pre-requisite, it proceeds further but then crashes on an npm command: execution error: /bin/sh: npm: command not found. I do have npm installed in vs code terminal and regular terminal.

So, I don't get why Teams Toolkit cannot find it

UPDATE: I figured it out. You have to install node at the operating system level via: https://nodejs.org/en/download. This will not recognize node/npm installed any other way such as through brew or nvm, which is pretty annoying.

ankitshubham97 commented 6 months ago

Hi @synth ! I followed your update and I am still unable to get it working. Here is what I did:

  1. Downloaded .dmg file: https://nodejs.org/dist/v18.18.2/node-v18.18.2.pkg
  2. The installer installed npm and node at /usr/local/bin/
  3. I restarted the VS Code.
  4. Still facing the same problem.

Could you help me figure out what I could have done wrong? cc: @swatDong

Tirlipinpin commented 6 months ago

I faced the same issue on my Macbook and found a solution, I hope it helps people around. I'm installed Node.js through nvm, which is itself loaded as an Oh my Zsh plugin. On an unrelated note to the Teams toolkit system, I wanted my prompt to load faster and enabled lazy loading for the nvm plugin in Oh my Zsh. Well, it seems that this is an issue for the Teams toolkit extension as it couldn't find Node.js anymore. Disabling the lazy loading and then restarting VSCode fixed the issue.