fastify-cli
fastify-cli copied to clipboard
Cannot use --require option is ESM project
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.23.2
Plugin version
No response
Node.js version
18.16
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.7
Description
My project was initialized with fastify-cli ESM template, and I added TypeScript.
I'm trying to use the require option of the CLI to load my opentelemetry setup before fastify, and I failed to make it work so far:
- adding 'require' option to my 'app.ts' module and adding the
--optionsflag when starting the app ignores my 'require' option - if I start the CLI with the
--requireoption it tries to load the file, but fails as it's an ESM module and it tries torequire()it. - I even tried converting the file I'm trying to load as a regular
.cjsfile, but when I try to require it explicitly specifying the .cjs extension it fails to find the file.
Any idea what I could do to make it work here?
Do you think it would be possible to use dynamic import() instead of require() in fastify-cli to support both CJS and ESM modules?
Steps to Reproduce
I have a branch with the setup here: https://github.com/Azure-Samples/azure-search-openai-javascript/tree/opentelemetry/packages/search
- git clone &&
npm install cd packages/searchnpm build && npm start
Expected Behavior
There should be a way to use require option in an ESM project.
The solution to this is to add a --import flag as well.
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
Hi @sinedied, I think we can close this issue now!
Thank you @weixinwu !