Firebase部署错误:找不到模块'@ babel / runtime / helpers / builtin / interopRequireDefault'

时间:2018-07-01 00:18:29

标签: javascript firebase material-ui babel

我正在尝试部署Firebase函数,但我真的很难解决多个问题。

当我尝试将应用程序部署到Firebase时,出现类似babel的错误:

i  deploying functions, hosting
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (56.91 KB) for uploading
✔  functions: functions folder uploaded successfully
i  hosting: preparing dev directory for upload...
✔  hosting: 4 files uploaded successfully
i  functions: updating function main...
⚠  functions[main]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module '@babel/runtime/helpers/builtin/interopRequireDefault'
    at Function.Module._resolveFilename (module.js:476:15)
    at Function.Module._load (module.js:424:25)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/user_code/node_modules/@material-ui/icons/ExpandMore.js:3:30)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)

当我导航到@babel/runtime/helpers/builtin/interopRequireDefault时,文件位于functions文件夹中。

我正在使用material-ui和reactjs。

错误仅在我尝试使用material-ui时显示,错误日志中指出了该错误。

package.json 内部函数:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "@material-ui/core": "^1.3.0",
    "@material-ui/icons": "^1.1.0",
    "express": "^4.16.3",
    "firebase-admin": "^5.12.1",
    "firebase-functions": "^1.1.0",
    "react": "^16.4.1",
    "react-dom": "^16.4.1"
  },
  "devDependencies": {
    "eslint": "^4.12.0",
    "eslint-plugin-promise": "^3.6.0"
  },
  "private": true
}

package.json 在项目文件夹的根目录中:

{
  "name": "Cards",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "babel": "babel src -d functions/src && babel index.js -d functions"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@material-ui/core": "^1.3.0",
    "@material-ui/icons": "^1.1.0",
    "firebase": "^5.2.0",
    "react": "^16.4.1",
    "react-dom": "^16.4.1"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "firebase-admin": "^5.12.1",
    "firebase-functions": "^1.1.0",
    "firebase-tools": "^3.19.1",
    "webpack": "^4.14.0",
    "webpack-dev-server": "^3.1.4"
  }
}

完成代码编写后,我运行npm run babel来转换代码并将其放入functions文件夹。然后我运行firebase deploy

那么,导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:0)

部署时也遇到问题,但通过安装

设法解决了这一问题
@babel/runtime 

作为功能文件夹中的devDependency。