如何在VS Code中部署Azure函数?

huangapple go评论64阅读模式
英文:

How do we deploy azure function in VS Code?

问题

我按照这里的部署指南精确地操作了:https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=nodejs#republish-project-files

然而,在部署后,在 Azure 门户中,函数应用中没有任何函数。

在 VS Code 中的输出日志中也有以下信息:

- /Users/myapp/code/test-azure-functions/node_modules/rimraf/dist/cjs/src/bin.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/myapp/code/test-azure-functions/node_modules/minipass/dist/cjs/index.js:13:23)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/myapp/code/test-azure-functions/node_modules/minipass/dist/cjs/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/path-scurry/dist/cjs/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/glob/dist/cjs/src/glob.js',
    '/Users/myapp/code/test-azure-functions/node_modules/glob/dist/cjs/src/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/rimraf/dist/cjs/src/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/rimraf/dist/cjs/src/bin.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-azure-functions@1.0.0 clean: `rimraf dist`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the test-azure-functions@1.0.0 clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我现在完全不知道该怎么办了。我该怎么做?

英文:

I followed the deployment guide precisely here https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=nodejs#republish-project-files

However, After deploying, In Azure portal, there is no functions in function app.

如何在VS Code中部署Azure函数?

And in the output log in VS code:

- /Users/myapp/code/test-azure-functions/node_modules/rimraf/dist/cjs/src/bin.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/myapp/code/test-azure-functions/node_modules/minipass/dist/cjs/index.js:13:23)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/myapp/code/test-azure-functions/node_modules/minipass/dist/cjs/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/path-scurry/dist/cjs/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/glob/dist/cjs/src/glob.js',
    '/Users/myapp/code/test-azure-functions/node_modules/glob/dist/cjs/src/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/rimraf/dist/cjs/src/index.js',
    '/Users/myapp/code/test-azure-functions/node_modules/rimraf/dist/cjs/src/bin.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-azure-functions@1.0.0 clean: `rimraf dist`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the test-azure-functions@1.0.0 clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I have completely no clue now.
What should I do?

答案1

得分: 1

I followed the given MS DOC and I can able to deploy my function to funtion app.

My function runs successfully locally as below,

如何在VS Code中部署Azure函数?

In order to use Azure Function Core tools command to deploy the Function like below:-

Open your Vs Code terminal and run the commands below:-

az login
az account set --subscription "subsription-name"
func azure functionapp publish functionapp-name

如何在VS Code中部署Azure函数?

如何在VS Code中部署Azure函数?

The function got deployed successfully to the function app at Azure Portal as below,

如何在VS Code中部署Azure函数?

The code runs successfully at Azure Portal also as below,

如何在VS Code中部署Azure函数?

Coming to your error code, Some times, there might be corruption in the node_modules directory. To fix this, delete the “node_modules” folder and reinstall all dependencies.

You can try the below command to install node_modules,

npm install rimraf --save-dev

Below is my package.json file,

package.json:

{
  "name": "your-project-name",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\"",
    "clean": "rimraf dist"
  },
  "devDependencies": {
    "rimraf": "^5.0.1"
  }
}

Run the below commands and try again,

npm install

Then try to run your code with fn+f5 and deploy that to function app.

英文:

I followed the given MS DOC and I can able to deploy my function to funtion app.

My function runs successfully locally as below,

如何在VS Code中部署Azure函数?

In order to use Azure Function Core tools command to deploy the Function like below:-

Open your Vs Code terminal and run the commands below:-

az login
az account set --subscription "subsription-name"
func azure functionapp publish functionapp-name

如何在VS Code中部署Azure函数?

如何在VS Code中部署Azure函数?

The function got deployed successfully to the function app at Azure Portal as below,

如何在VS Code中部署Azure函数?

The code runs successfully at Azure Portal also as below,

如何在VS Code中部署Azure函数?

Coming to your error code, Some times, there might be corruption in the node_modules directory. To fix this, delete the “node_modules” folder and reinstall all dependencies.

You can try the below command to install node_modules,

npm install rimraf --save-dev

Below is my package.json file,

package.json:

{
  "name": "your-project-name",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\"",
    "clean": "rimraf dist"
  },
  "devDependencies": {
    "rimraf": "^5.0.1"
  }
}

Run the below commands and try again,

npm install

Then try to run your code with fn+f5 and deploy that to function app.

答案2

得分: 0

看起来在部署之前我没有成功构建:

我需要先运行这个命令:

npm run-scripts build

然后构建完成后会生成一个 dist 文件夹。

然后我可以继续执行部署步骤,函数就会出现。

英文:

Looks like I failed to build before deploying:

I need to run this first:

npm run-scripts build

Then a dist folder will be generated after the build.

Then I can do the deploying steps, and the function would appear.

huangapple
  • 本文由 发表于 2023年7月20日 13:09:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定