Eli*_*hen 11 typescript google-cloud-functions firebase-cli
我有一个名为的子模块shared
,它位于backend
文件夹(即云函数文件夹)旁边:
我已经添加了局部依赖shared
于backend/package.json
像这样:
"dependencies": {
...
"shared": "file:../shared"
}
Run Code Online (Sandbox Code Playgroud)
我跑了npm install
并确保它node_modules/shared
存在。虽然,当我运行以下代码时:
firebase deploy --only functions
Run Code Online (Sandbox Code Playgroud)
我收到以下错误(通过 firebase):
Error: Error parsing triggers: Cannot find module 'shared/common'
Try running "npm install" in your functions directory before deploying.
Run Code Online (Sandbox Code Playgroud)
此错误是由于此行:
import { currentWeek } from 'shared/common';
Run Code Online (Sandbox Code Playgroud)
如果我将目录更改为../../../shared/common
,firebase 将编译而不会出现任何错误。
export { currentWeek } from './current-week';
Run Code Online (Sandbox Code Playgroud)
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"module": "commonjs",
"declaration": true,
"strict": true,
"removeComments": true
}
}
Run Code Online (Sandbox Code Playgroud)
{
"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/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
如果我有这个模块,为什么会出现这个错误?有什么我想念的吗?
我认为,你必须配置module-resolution
打字稿编译器。
对于你的情况:
{
"compilerOptions": {
"baseUrl": ".", // This must be specified if "paths" is.
"paths": {
"shared/*": ["../shared/*"] // This mapping is relative to "baseUrl".
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以shared
用其他名称命名。
{
"compilerOptions": {
"baseUrl": ".", // This must be specified if "paths" is.
"paths": {
"myLib/*": ["../shared/*"] // This mapping is relative to "baseUrl".
}
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
import { currentWeek } from "myLib/common";
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1155 次 |
最近记录: |