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

pode CLI cmd does not work as expected. Causes The term './Server.ps1' is not recognized as the name of a cmdlet, function, script or operable program #429

Closed
larssb opened this issue Dec 12, 2019 · 6 comments · Fixed by #438
Assignees
Labels
Milestone

Comments

@larssb
Copy link

larssb commented Dec 12, 2019

Describe the Bug

pode cli cmd start does throws. The term './Server.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Steps To Reproduce

Steps to reproduce the behavior:
0. Execute pode init

  1. Go to the root of your project using pode
  2. Execute pode start
  3. See error

Expected Behavior

I expected pode start to work by starting the Pode server.

Platform

  • OS: Win10 build 1809
  • PS Version: v5.1
  • Pode version: v1.2.1

Additional Context

In my troubleshooting I went through the Pode code used to start the server. Here I see that on the Windows platform, the server is initiated by executing powershell /c "$($ActionScript)". This seems to be the culprit.

When trying powershell /? in e.g. -> WindowsKey+R. I don't see the /c option anywhere. Shouldn't it be the -Command parameter that was used here instead?
Anyways PowerShell do not interpret the $(ActionScript) part as executable code. I've successfully used the following approact: powershell -command & { POWERSHELL_CODE_TO_EXECUTE }


I hope I describe myself clearly in the above. If not I'll be happy to further elaborate.

Thank you

@Badgerati
Copy link
Owner

Hey @larssb,

So for /c I definitely agree that needs to be -Command for powershelll and pwsh - though I will mention that powershell /c does work on my machine (same platform/versions):

PS> powershell /c "write-host 'hello'"
hello
PS> powershell -c "write-host 'hello'"
hello

I did replace powershell /c "$($ActionScript)" with powershell -Command "$($ActionScript)" and it works as intended 🤔

The only way I could get the same error was to follow your steps literally:

  1. Run pode init
  2. Run pode start

I noticed that between the two you're not creating a server.ps1 script, and for me this is when the error was thrown:

C:\Projects\Temp> pode init
name (Temp):
version (1.0.0):
description:
entry point (./server.ps1):
author:
license (MIT):
Success, saved package.json

C:\Projects\Temp> pode start
./server.ps1 : The term './server.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ ./server.ps1
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./server.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Is this the same case for yourself? In which case would you prefer pode init create the initial server script if it doesn't already exist?

@larssb
Copy link
Author

larssb commented Dec 13, 2019

Hi @Badgerati

Thank you for replying so fast. I did have a Server.ps1 file before executing pode start. However, it is in a sub-folder .... so

Folder hierarchy

  • package.json
    -- API
    --- Server.ps1

However, I do not see why this should not work. Of course I updated the package.json after executing pode init so that it has the corrects paths.

I just tried dot invoking. So in Setup.ps1 on L17 I did . "$($ActionScript)". And that works without issues.

I also tried moving my Server.ps1 file into my projects root folder. So that is side-by-side the package.json file. Update the package.json file to reflect this.

Same error:

The term './Server.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

So maybe dot-invocation is the way to go? What do you think?

@Badgerati
Copy link
Owner

Hi @larssb,

So a sub-folder was what I was missing before, but I've just tried it on my side and it works 😕. This is the folder hierarchy and package.json I have:

  • Hierarchy:
- package.json
- api/
    - server.ps1
  • package.json:
{
    "version":  "1.0.0",
    "license":  "MIT",
    "name":  "test",
    "scripts":  {
                    "test":  "invoke-pester ./tests/*.ps1",
                    "install":  "yarn install --force --ignore-scripts --modules-folder pode_modules",
                    "build":  "psake",
                    "start":  "./api/server.ps1"
                },
    "description":  "",
    "author":  "",
    "main":  "./api/server.ps1"
}

Running pode start in the same directory as the package.json works 🤔. Would you be able to share your package.json as well? (assuming the hierarchy is the one you mentioned above)

On the dot-invocation, I was originally using that method! Unfortunately it was causing havoc with the FileWatcher, and using powershell.exe/pwsh.exe worked. I'll test it again though, that and Invoke-Expression, just to make sure I haven't since fixed the issue during the massive refactor 👀

@Badgerati Badgerati self-assigned this Dec 16, 2019
@Badgerati
Copy link
Owner

Hey @larssb,

Good news! Using Invoke-Expression works, so I must have fixed whatever the original issue was way-back-when. It's also nice to remove the "pwsh,exe"/"powershell.exe" check!

Let me know if Invoke-Expression works for you - I did check dot-invocation as well, just this is a little nicer.

@larssb
Copy link
Author

larssb commented Dec 20, 2019

Yes that works. I just tested it. Looks great. Hopefully this can get out in the next release of Pode.

Good 1

@Badgerati
Copy link
Owner

Excellent! Yes, I'll get this into the next release.

@Badgerati Badgerati mentioned this issue Dec 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants