【问题标题】:TypeScript functions on Firebase - paths problemFirebase 上的 TypeScript 函数 - 路径问题
【发布时间】:2021-05-23 11:19:51
【问题描述】:

我的 Firebase 项目具有使用以下目录层次结构实现的 TypeScript 函数:

- functions
  - src
    - index.ts
  - shared
    - other.ts
  - tsconfig.json
  - package.json

我的tsconfig.json 文件如下所示:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "resolveJsonModule": true
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

还有我的package.json

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc -b",
    "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",
    "test": "mocha --reporter spec 'test/**/*.ts'" 
  },
  "engines": {
    "node": "12"
  },
  "main": "lib/index.js",
  "dependencies": {
     "dep": "^1.0.0"
  }
}

我可以使用npm run build(转换为tsc -b)编译项目,但由于以下错误而无法服务(firebase emulators:start):

错误:找不到模块“./functions/lib/index.js”。请验证 package.json 是否有有效的“main”条目

令我惊讶的是,lib 文件夹包含两个新的 srcshared 文件夹,而不是直接在其下的“已编译”JS。我该如何解决?

【问题讨论】:

  • tsc后,检查lib文件夹的内容
  • 正如我所写,内容是两个目录(src & shared),其中src 包含index.js

标签: typescript firebase


【解决方案1】:

在 package.json 中你需要添加以下内容

"main": "lib/src/index.js",

正如您所提到的,这是因为这两个文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多