Firebase云函数日志中出现“找不到模块”错误

4
我正在尝试使用云函数和NextJS提供动态内容。当我运行“firebase serve”时,一切都按预期在本地工作。但是,当我运行“firebase deploy”并尝试运行我的函数时,我在Firebase函数日志中收到以下错误信息。请保留HTML标签。

我正在尝试使用云函数NextJS提供动态内容。

当我运行firebase serve时,一切都按预期在本地工作。

但是,当我运行firebase deploy并尝试运行我的函数时,我在Firebase函数日志中收到以下错误信息。

enter image description here

Error: Cannot find module 'babel-runtime/core-js/object/get-prototype-of'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/user_code/next/dist/pages/_document.js:7:23)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

我不直接使用babel(我使用typescript),所以我的一个模块必须使用它作为依赖项之一。
我猜我在本地机器上全局安装了某些东西,但在我的云函数中不存在,但是我该如何调试这个问题呢?我已经尝试将babel-runtime添加到我的package.json中。
node -v v6.11.5

package.json

{
  "name": "functions",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "lint": "./node_modules/.bin/tslint -p tslint.json",
    "build-js": "./node_modules/.bin/tslint -p tslint.json && ./node_modules/.bin/tsc && cp package.json ../../build/functions/package.json"
  },
  "main": "index.js",
  "dependencies": {
    "async": "^2.6.0",
    "@babel/runtime": "^7.0.0-beta.39",
    "express": "^4.15.4",
    "firebase-admin": "~5.8.1",
    "firebase-functions": "^0.8.1",
    "googleapis": "^23.0.0",
    "next": "^4.2.1",
    "range-inclusive": "^1.0.2",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "request": "^2.83.0",
    "request-promise": "^4.2.2",
    "typescript": "^2.7.1"
  },
  "devDependencies": {
    "@babel/preset-env": "^7.0.0-beta.39",
    "babel-runtime": "^6.26.0",
    "tslint": "^5.8.0",
    "typescript": "^2.7.1"
  },
  "private": true
}

2
通常情况下,您不会将TypeScript添加为常规依赖项。它应该是一种开发依赖项,仅在构建时用于生成要部署的JS代码。哦,而且您正在直接使用@babel/runtime,这是否是您想要的?您真的需要同时使用TypeScript和Babel吗? - Doug Stevenson
1
我只会使用 Firebase CLI 提供的 TypeScript 配置,不会使用其他任何配置。 - Doug Stevenson
1
@MartinReiche 我搞定了。我用src/app和src/functions架构了我的应用程序。我将我在应用程序中需要的任何npm依赖项(我的React应用程序)也添加到了src/functions/package.json中,这解决了问题。这样说清楚了吗?如果你把代码放在gist或者其他地方,那么欢迎分享给我看一下。我可以看看是否有什么建议? - ak85
1
@ak85,感谢您的回答,我也用同样的方法解决了这个问题 :) - Martin Reiche
1
我也遇到了同样的问题。我的依赖项中没有包括typescript或babel。"@firebase/firestore": "^1.17.0", "@google-cloud/storage": "^5.8.5", "@types/sharp": "^0.28.3", "algoliasearch": "^4.5.1", "express": "4.17.1", "firebase": "7.21.0", "firebase-admin": "^9.2.0", "firebase-functions": "^3.11.0", "geo-tz": "^6.0.1", "lodash": "^4.17.20", "luxon": "^1.28.0", "mailchimp-api-v3": "^1.14.0", "request": "^2.88.2", "request-promise": "4.2.5", "sharp": "^0.28.3", "twilio": "^3.52.0" - Sunil Chauhan
显示剩余3条评论
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接