New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find module '@custom-modules/moduleName' when deploy using TypeScript #986
Comments
As my understanding works, That said, the error is coming from the fact that in the deployment process, the CLI interprets the functions code to understand what functions need to be deployed. Since the functions code is requiring a module that it has no knowledge of (this is in the If you are trying to save some typing by doing |
Hi there! Want to add more info for this issue, because I've encountered it as well. Having relative paths seems very inconvenient for me, because I have kinda So maybe there's a way to add this |
I have found that https://www.npmjs.com/package/module-alias worked for me.
|
Thx @izakfilmalter If you use the base url as described in https://create-react-app.dev/docs/importing-a-component/#absolute-imports, you can fix the absolute import errors the following way:
{
"compilerOptions": {
"baseUrl": "src",
"outDir": "lib"
},
"include": ["src"]
}
import { addPath } from 'module-alias'
addPath('./lib')
import './fix-ts-paths'
export * from './functions'
// normal functions code, using absolute imports Since absolute imports are commonly used, would it make sense to document this in the official firebase functions documentation @bkendall? |
Almost two years with no Optimal solution. for anyone who still struggles with this issue, but the below code at the top of the entry point file (main.ts).
|
why this is closed? |
Here it still output |
I try that, but for some reason this not works on |
The simplest solution is to just add tsc-alias to your build step. Changing |
Just to expand on @khevamann's response here, the neatest way to do this is to use tsc-alias. On {
"compilerOptions": {
...
"baseUrl": "./src",
"paths": {
"@constants/*": ["api/constants/*"],
"@interfaces/*": ["api/interfaces/*"],
"@middlewares/*": ["api/middlewares/*"],
"@modules/*": ["api/modules/*"],
"@services/*": ["api/services/*"]
},
...
} Then, change your ...
"scripts": {
"build": "tsc && tsc-alias",
"build:watch": "tsc-alias --watch",
"serve": "concurrently --kill-others \"firebase emulators:start --only functions\" \"npm run build:watch\"",
...
},
... ☝️ here I'm using And that's it. You can now import stuff using your defined paths, like: import { messages } from '@constants/responses'
import CandidatesService from '@modules/candidates/candidates.service'
import { IModule } from '@interfaces/module.interface' etc... |
Hey @leonardorb, thank you for your guide on how to work around this limitation. I have been trying to do as you described in your answer, but it seems that I'm not able to make it work.
I really don't know what else to try, would you mind taking a look at my project config? Here's the structure of my Here's the content of my
Here's the content of my
|
Using @leonardorb answer works, but not with the "scripts": {
"build": "tsc && tsc-alias",
"build:watch": "tsc --watch & tsc-alias --watch",
}, |
these issues took me hours, so I want to share what works for me so you don't have to...
|
Hey, guys~ I can't deploy when I assign a
paths
arguments intsconfig.json
, like this:The
paths
arguments usually using TypeScript and it work perfectly. But firebase deploy throw that error:This question has published in StackOverFlow before How to use TS Path Mapping with Firebase Cloud Functions, and for now, Can anyone help me? Thanks~ 🤣
The text was updated successfully, but these errors were encountered: