我在尝试将一个函数部署到firebase时遇到了一个问题。
构建失败:npm错误!无法读取undefined`的属性'body-parser'。
我在使用node版本18时没有得到错误:
...
"engines": {
"node": "18"
},
...
字符串
但是,我需要使用节点版本14,因为我正在连接到旧版本的MSSQL。
package.json
{
"name": "functions",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "lib/index.js",
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"mssql": "^9.1.1",
"short-uuid": "^4.2.2",
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.0"
},
"devDependencies": {
"@types/mssql": "^8.1.2",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/node": "^20.4.5",
"@types/body-parser": "^1.19.2",
"concurrently": "^8.2.0",
"nodemon": "^3.0.1",
"typescript": "^4.5.4",
"firebase-functions-test": "^3.0.0"
},
"private": true
}
型
firebase.json
...
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
...
型
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2019",
"esModuleInterop": true,
},
"compileOnSave": true,
"include": [
"src"
]
}
型
如何才能使用版本14进行部署?
1条答案
按热度按时间ha5z0ras1#
我删除了
package-lock.json
,它工作了。