Typescript Firebase部署-找不到本地依赖项的模块
我有一个名为Typescript Firebase部署-找不到本地依赖项的模块,typescript,google-cloud-functions,firebase-cli,Typescript,Google Cloud Functions,Firebase Cli,我有一个名为shared的子模块,它位于backend文件夹(即云功能文件夹)旁边: 我在backend/package.json中添加了本地依赖项shared,如下所示: "dependencies": { ... "shared": "file:../shared" } 我运行了npm安装,并确保node\u模块/shared存在。但是,当我运行以下代码时: firebase deploy --only functions 我得到以下错误(由firebase提供): 此
shared
的子模块,它位于backend
文件夹(即云功能文件夹)旁边:
我在backend/package.json
中添加了本地依赖项shared
,如下所示:
"dependencies": {
...
"shared": "file:../shared"
}
我运行了npm安装
,并确保node\u模块/shared
存在。但是,当我运行以下代码时:
firebase deploy --only functions
我得到以下错误(由firebase提供):
此错误是由以下行引起的:
import { currentWeek } from 'shared/common';
如果我将目录更改为。/../../../shared/common
,firebase将编译时不会出现任何错误
共享/公共/索引.ts: 共享/tsconfig.json: backend/tsconfig.json:
如果我有这个模块,为什么会出现这个错误?有什么我遗漏的吗?我想,您必须为typescript编译器配置模块解析 对于您的情况:
{
"compilerOptions": {
"baseUrl": ".", // This must be specified if "paths" is.
"paths": {
"shared/*": ["../shared/*"] // This mapping is relative to "baseUrl".
}
}
}
您可以用另一个名称命名shared
{
"compilerOptions": {
"baseUrl": ".", // This must be specified if "paths" is.
"paths": {
"myLib/*": ["../shared/*"] // This mapping is relative to "baseUrl".
}
}
}
用法:
import { currentWeek } from "myLib/common";
如果我将
共享
文件夹添加到路径
,那么我也必须将其添加到包含
,这会导致相同的错误。唯一的区别是,共享的
将不在节点单元模块中
(这再次引出了一个问题-为什么firebase找不到它?我假设它在外部运行npm安装,结果是404。你有没有找到解决方案?有相同的解决方案problem@Jonovono不,我必须相对导入(../../)
{
"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/**/*"
]
}
{
"compilerOptions": {
"baseUrl": ".", // This must be specified if "paths" is.
"paths": {
"shared/*": ["../shared/*"] // This mapping is relative to "baseUrl".
}
}
}
{
"compilerOptions": {
"baseUrl": ".", // This must be specified if "paths" is.
"paths": {
"myLib/*": ["../shared/*"] // This mapping is relative to "baseUrl".
}
}
}
import { currentWeek } from "myLib/common";