【发布时间】:2019-07-15 22:49:00
【问题描述】:
我有一个名为 shared 的子模块,它位于 backend 文件夹(即云函数文件夹)旁边:
我在backend/package.json 中添加了本地依赖项shared,如下所示:
"dependencies": {
...
"shared": "file:../shared"
}
我运行npm install 并确保node_modules/shared 存在。虽然,当我运行以下代码时:
firebase deploy --only functions
我收到以下错误(通过 firebase):
Error: Error parsing triggers: Cannot find module 'shared/common'
Try running "npm install" in your functions directory before deploying.
这个错误是由于这一行:
import { currentWeek } from 'shared/common';
如果我将目录更改为../../../shared/common,firebase 将编译没有任何错误。
shared/common/index.ts:
export { currentWeek } from './current-week';
shared/tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"module": "commonjs",
"declaration": true,
"strict": true,
"removeComments": true
}
}
后端/tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"outDir": "./dist",
"module": "commonjs",
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"target": "es6",
"moduleResolution": "node",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2015",
"dom"
]
},
"include": [
"./src/**/*",
"../shared/**/*"
]
}
如果我有这个模块,为什么会出现这个错误?我有什么遗漏吗?
【问题讨论】:
-
你有没有想过解决这个问题?遇到同样的问题
-
@Jonovono 不,我必须相对导入它(../../)
标签: typescript google-cloud-functions firebase-cli