azure-functions-powershell-worker icon indicating copy to clipboard operation
azure-functions-powershell-worker copied to clipboard

using module shows error in vscode, but works when debugging locally

Open mgeorgebrown89 opened this issue 6 years ago • 3 comments

I have a module in the Module folder at the root path of my Azure Functions App. Locally, to get these to import, I have to use the full path or a relative path. No problems there. When I debug it locally and call my function, it doesn't load it.

Since these modules are added to $env:PSModulePath at runtime, I can just say using module ModuleName and it works when I call the funciton, but VSCode highlights the line with the squiggly red underlines.

It should be able to do something similar, but I haven't found a solution. I tried the profile.ps1, but no dice.

mgeorgebrown89 avatar May 02 '19 16:05 mgeorgebrown89

Thanks for reporting the issue. Yes, the module path is currently a gap in the developer experience. There needs to be a way to update the module path of the integrated powershell console when working with a PS Azure function app. Maybe powershell extension should start a new integrated PS console with the updated module path in that case.

/cc @TylerLeonhardt

daxian-dbw avatar May 05 '19 08:05 daxian-dbw

The solution here is to do one of two things:

  • Install-Module/Update-Module and Save-Module so that you have the module in both your PSModulePath and your local function app directory
  • Add the local function app Modules directory to process-level PSModulePath

Realistically, we need something like a venv for PowerShell that gives you a "Functions dev environment" once you enter a function app directory (e.g. Enter/Exit-FuncEnvironment) where you have the special types (e.g. HttpResponseContext), your PSModulePath gets the local Modules directory, and maybe modify your prompt to denote that you're in a session of some kind.

Then, we could modify the VS Code extension to automatically enter that session when you open a workspace that's detected as a function app.

/cc @Francisco-Gamino this would likely serve as the "helper module" we discussed before

joeyaiello avatar May 09 '19 22:05 joeyaiello

Will document this and also look to add to the VS Code extension.

eamonoreilly avatar Sep 25 '19 21:09 eamonoreilly