您好,当该项目包含另一个打字稿依赖项时,我会通过firebase-tools将我的打字稿Express应用程序部署到firebase时遇到问题。在google函数中运行时,构建过程可能出了点问题。请注意,该程序在本地可以按预期工作,这只是部署问题。
这是MVE的仓库:
https://github.com/jk89/baseRepo
加载两个依赖项:
https://github.com/jk89/depRepo1
https://github.com/jk89/depRepo2
我从firebase-tools'firebase deploy'中收到以下错误:
jty@carrot:~/April2018/typescript-min-ver/baseRepo$ firebase deploy
=== Deploying to 'pricecalculator-e88d6'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build
> base-repo@0.1.0 build /home/jty/April2018/typescript-min-ver/baseRepo
> npm run tslint && tsc --declaration
> base-repo@0.1.0 tslint /home/jty/April2018/typescript-min-ver/baseRepo
> tslint -c tslint.json -p tsconfig.json
✔ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing . directory for uploading...
i functions: packaged . (12.76 KB) for uploading
✔ functions: . folder uploaded successfully
i functions: updating Node.js 8 function webApi(us-central1)...
⚠ functions[webApi(us-central1)]: Deployment error.
Function load error: Code in file ./lib/index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'dep-repo-1'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/lib/index.js:7:22)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Functions deploy had errors. To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Having trouble? Try firebase deploy --help
当然这是使用模块化打字稿模块的常见用例。我不明白为什么它不起作用?!
答案 0 :(得分:8)
当Firebase尝试安装和构建功能时,它将查看dep-repo-1 / package.json "module": "./dist/index.js"
中的字段并尝试遵循该字段。由于该文件不存在,它会抛出Error: Cannot find module 'dep-repo-1'
该文件不存在,因为在每个子模块中,dist
目录未发布到Github,并且Firebase不会自动构建您的npm软件包。 (dist/
包含在.gitignore
中)
有一些关于如何构建模块的选项:
dist/
,而忽略lib/
)。这类似于设置使用npm publish
的模块的方式。dist/
目录。这不太干净(因为您将应将内置文件包括在仅源存储库中)"install": "tsc"
。这将在您执行npm安装时运行。请确保将Typescript添加到您的依赖项列表中,因为Firebase构建环境尚未预安装它。