gpt4 book ai didi

node.js - 使用 Azure DevOps 部署 Azure Function 时出现 @prisma/client 错误

转载 作者:行者123 更新时间:2023-12-03 02:02:13 25 4
gpt4 key购买 nike

我正在尝试使用 Azure DevOps 部署包含 Node.js 和 TypeScript 的 Azure Function。

我的项目使用 Prisma 连接到 MongoDB 数据库。
当我尝试部署我的函数时,遇到以下错误:

@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.

但是,Prisma 在我的本地计算机上运行良好。我认为这是一个与 Prisma 相关的问题,因为另一个不使用 Prisma 的函数部署成功。

这是我的 package.json:

{
"name": "testtsnode",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"prestart": "npx prisma generate && npm run build",
"start": "func start",
"test": "echo \"No tests yet...\"",
"prisma:g": "npx prisma generate",
"prisma:s": "npx prisma studio"
},
"dependencies": {
"@prisma/client": "^4.11.0",
"mongodb": "^5.1.0",
"tsc-silent": "^1.2.2"
},
"devDependencies": {
"@azure/functions": "^3.0.0",
"@types/node": "^16.x",
"typescript": "^4.0.0"
}
}

Here's my devops setting

这是我的 yaml 格式的 DevOps 设置

pool:
name: Azure Pipelines
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --output ./bin
fi
displayName: 'Build extensions'

- task: NodeTool@0
displayName: 'Use Node version 18.15.0'
inputs:
versionSpec: 18.15.0

- task: Npm@1
displayName: 'Install Application Dependencies'
inputs:
workingDir: '$(System.DefaultWorkingDirectory)'
verbose: false

- task: Npm@1
displayName: 'Run ''build'' script'
inputs:
command: custom
workingDir: '$(System.DefaultWorkingDirectory)'
verbose: false
customCommand: 'run build --if-present'

- task: Npm@1
displayName: 'Remove extraneous packages'
inputs:
command: custom
workingDir: '$(System.DefaultWorkingDirectory)'
verbose: false
customCommand: 'prune --production'

- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false

- task: AzureFunctionApp@2
displayName: 'Azure Function App Deploy'
inputs:
azureSubscription: DevOps
appType: functionAppLinux
appName: tsnodefunction20230315
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'

我尝试在安装后和预启动中添加 npx prisma 生成。
我还尝试更改 prisma generated 的输出位置
以上两个都不起作用。

使用 Azure DevOps 部署 Azure Function 时如何解决此错误?
任何帮助将不胜感激!

最佳答案

对于prisma没有初始化错误:

@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.

我在构建脚本中包含了 npx prismagenerate 命令

"scripts": {
"build": "npx prisma generate && nest build",
...
}

您也遵循类似的方式。这解决了我在 spinnaker 上运行 docker 镜像的问题。

关于node.js - 使用 Azure DevOps 部署 Azure Function 时出现 @prisma/client 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75747468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com