-
Notifications
You must be signed in to change notification settings - Fork 976
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 start firebase emulator functions with node 14. ES Module import failure on windows. #3573
Comments
I have a proposed fix on branch > git clone https://github.com/firebase/firebase-tools.git
> cd firebase-tools
> git checkout origin/dl-cf3-esm-windows
> npm i
> npm run build
> npm link # firebase cli should now point to locally built one
# cd to your functions project
> firebase functions:shell |
Thanks, gave it a try and it produced the following error(see attached)... although the file does exist.
I am using Nodejs 14.17.3, tsconfig is set for es2020 with package.json's type as "module" |
This looks like the same result I got when I tried to use pathToUrl by editing the firebase-tools files inside of node_modules.. Is this the same? If so, I can attest, that it did not work in my case, either. |
I think it is not working because the import statements do not have the Manually going and adding
Using webpack too resulted in an error: |
@paulvanj You may already know now, but you need to include // BAD
import Setup from './utils/setup'
// GOOD
import Setup from './utils/setup.js' @DibyodyutiMondal Curious, are you required to use ES module in your setup? In most cases, you would setup in (I'm closing the issue, as I think the reported issue is now answered. Feel free to re-open if you are still having a problem @paulvanj ). |
Oops. I forgot that the original issue is still unfixed in the main branch. I'll get a PR setup and actually release a fix before closing the issue. |
Well, you are right - since I am using Typescript anyway, from a development perspective, I don't need to worry if the transpiled cloud-functions code is commonjs or esm. However, the cloud-functions code references libraries containing data models and the like, that are also used by my front-end angular app. Since functions-framework can only load commonjs, these libraries must also be in commonjs, which then results in angular not being able to tree-shake them, increasing the size of the website distribution. Hence my high preference to be able to use esm. (Also, being able to use top-level await to perform some of the setup actions is going to be cool for code ergonomics, but it's not as much a pain point as the bloating libraries issue) |
@DibyodyutiMondal Thanks for sharing your setup. It sounds advanced, and I'm glad to have a chance to learn how functions is being used by our advanced users. It sounds like using Typescript (along with Webpaxk) with ES module is a tricky business, and I'm not too familiar with these techs to offer useful advice 😢. I am personally curious and going to try different setups to see if we can come up with a good starting template. Would appreciate if you can share what you learn from your setup. |
Sure, I would love to do that. Is there a designated place for that already, or I can just do that here? Right now, the best solution I can come up off the top of my head is that any libraries built for both web and cloud-functions must be compiled twice (once for esm, once for commonjs) and then the results be bundled together, so consumers can choose the version they need. As for the 'how' to do that - I too will have to experiment. |
@DibyodyutiMondal This is probably a good place to start. Once we have some concrete patterns and recommendations we can suggest, I will work with our DevRel team to find a good place to share the content so other users can learn from it. Again, thanks for being on the bleeding edge and being proactive about your issues. |
I am getting the following error:
Is there anything I can do from my side to solve this problem, or am I forced to use commonjs as long as I am developing on windows? (I do not like the idea of adding
simport
throughout the entire dependency chain of my cloud-functions code.)Originally posted by @DibyodyutiMondal in #2994 (comment)
The text was updated successfully, but these errors were encountered: