zip-it-and-ship-it icon indicating copy to clipboard operation
zip-it-and-ship-it copied to clipboard

experimentalDecorators / emitDecoratorMetadata not supported in netlify CLI

Open tomardern opened this issue 3 years ago • 4 comments
trafficstars

Is your feature request related to a problem? Please describe.

We are trying to use the popular https://github.com/microsoft/tsyringe dependancy injection package within netlify functions. This does not seem to be working, and we are getting the following error:

Error: TypeInfo not known for "X"
  InternalDependencyContainer.construct (<project-path>/node_modules/tsyringe/dist/cjs/dependency-container.js:263:23)
  InternalDependencyContainer.resolve (<project-path>/node_modules/tsyringe/dist/cjs/dependency-container.js:105:33)
  Object.<anonymous> (<project-path>/src/main.ts:51:32)
  Module._compile (internal/modules/cjs/loader.js:999:30)
  Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
  Module.load (internal/modules/cjs/loader.js:863:32)
  Function.Module._load (internal/modules/cjs/loader.js:708:14)
  Module.require (internal/modules/cjs/loader.js:887:19)
  require (internal/modules/cjs/helpers.js:74:18)
  Object.<anonymous> (<project-path>/.netlify/functions-serve/incoming/incoming.js:1:18)

I think the underlying issue is that Netlify CLI uses esbuild bundler under-the-hood (https://www.netlify.com/blog/2021/04/02/modern-faster-netlify-functions/), which in turn does not support experimentalDecorators and emitDecoratorMetadata (https://github.com/evanw/esbuild/issues/257).

The solution could be to use https://github.com/thomaschaaf/esbuild-plugin-tsc but there is no way (that I've found) to modify the netlify CLI's esbuild config

Describe the solution you'd like

A way of modifying the esbuild config during netlify dev commands.

Describe alternatives you've considered

N/a

Additional context

N/a

Can you submit a pull request?

No.

Pull requests are welcome! If you would like to help us add this feature, please check our contributions guidelines.

tomardern avatar Feb 22 '22 19:02 tomardern

Should we add a flag for the plugin to use?

iib0011 avatar Feb 25 '22 14:02 iib0011

Maybe something in the toml file? eg

[functions]
  directory = "src/"
  node_bundler = "esbuild"
  esbuild_config_file = "./config_file"  # Specifies `esbuild` config

tomardern avatar Feb 28 '22 10:02 tomardern

Okay

iib0011 avatar Feb 28 '22 10:02 iib0011

Hi all 👋 This issue belongs in https://github.com/netlify/zip-it-and-ship-it. I'm trying to transfer it, however GitHub seems to dislike it.

For esbuild plugins support you might want to look at the discussion in https://github.com/netlify/zip-it-and-ship-it/issues/392

erezrokah avatar Feb 28 '22 11:02 erezrokah