Skip to content
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

How to use with NestJs and decoration #183

Open
chrisDupuis opened this issue Jan 16, 2024 · 7 comments
Open

How to use with NestJs and decoration #183

chrisDupuis opened this issue Jan 16, 2024 · 7 comments

Comments

@chrisDupuis
Copy link

My project use NestJs for firebase function.

All injection are null when running on firebase function.
They re a lot of claim about esbuild and NestJs.

Does someone use NestJs with simondotm/nx-firebase plugIn ?
How to use it with NestJs ?

@chrisDupuis chrisDupuis changed the title How to use with NestJs and annotation How to use with NestJs and decoration Jan 21, 2024
@chrisDupuis
Copy link
Author

My solution is to replace @nx/esbuild:esbuild with
the @nx/webpack:webpack
and configure correctly the web pack config.

@simondotm
Copy link
Owner

That's interesting to know @chrisDupuis thanks.

Yes, the plugin's use of esbuild for bundling functions is just one option. Webpack or rollup are also possible, just with the necessary changes to project.json for your functions.

@simondotm
Copy link
Owner

I would be interested in any links you might have for how esbuild might not be compatible with NestJs.

@simondotm
Copy link
Owner

Ah, just done a little research and I understand the issue now - esbuild by design does not handle typescript decorators. That is not great news and I didnt know this about esbuild.

Someone here is talking about using an esbuild plugin to pre-compile typescript before esbuild gets it.

https://hackernoon.com/using-typescript-decorators-with-esbuild

@Gurey
Copy link

Gurey commented Feb 19, 2024

We also solved it by using webpack instead of esbuild

This was some time ago so i am not 100% sure this config works today.

but in the project.json file set the targets.build to

    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "target": "node",
        "compiler": "tsc",
        "outputPath": "dist/apps/<APP_NAME>",
        "main": "apps/<APP_NAME>/src/main.ts",
        "tsConfig": "apps/<APP_NAME>/tsconfig.app.json",
        "assets": [
          "apps/<APP_NAME>/src/assets",
          {
            "glob": "**/*",
            "input": "apps/firebase/environment",
            "output": "."
          }
        ],
        "isolatedConfig": true,
        "webpackConfig": "apps/<APP_NAME>/webpack.config.js",
        "generatePackageJson": true
      },
      "configurations": {
        "development": {},
        "production": {}
      }
    },

And the webpack.config.js looks like

const { composePlugins, withNx } = require('@nx/webpack')

// Nx plugins for webpack.
module.exports = composePlugins(withNx(), config => {
  // Update the webpack config as needed here.
  // e.g. `config.plugins.push(new MyPlugin())`
  return config
})

@simondotm
Copy link
Owner

Thanks @Gurey
I think at some point I'll look into making the choice of bundler an option for functions.

@simondotm
Copy link
Owner

simondotm commented Mar 24, 2024

As mentioned in the article I linked above, this esbuild plugin seems to be the way to go for decorators with esbuild.

https://github.com/thomaschaaf/esbuild-plugin-tsc

Would require an esbuild config for function projects that use decorators, so if anyone is able to experiment with this and share their solution that would be great.

https://nx.dev/nx-api/esbuild/executors/esbuild#esbuildconfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants