Support ESM for exporting server `--options`
See original GitHub issueIt would be great if ESM projects could export const options
when using the --options
flag.
Like this:
export default async (fastify, opts) => {
// ...
}
export const options = {
maxParamLength: 200,
}
For now, this seems to work:
async function server(fastify, opts) {
// ...
}
server.options = {
maxParamLength: 200,
}
export default server
Not the end of the world, but I did spin my wheels for a bit thinking export const options
would just work, since ESM is supported otherwise.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Getting Started with (and Surviving) Node.js ESM
Fortunately, the exports scheme supports wildcards and many other options to make exposing lots of subpath resources in your libraries easier.
Read more >What does it take to support Node.js ESM? – The Guild
exports is available, and since support for Node.js v10.x is dropped, everything should be fine and supporting ESM shouldn't be that hard. After ......
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
The assert { type: 'json' } syntax is mandatory; see Import Assertions. The imported JSON only exposes a default export. There is no...
Read more >Using ECMAScript modules (ESM) with Node.js
Learn about using ES modules in Node.js today and get a closer look at how you can migrate your codebase to make use...
Read more >Support ES module format (ESM) in next.config.js #32239
I had to include babel-jest to be able to use Jest. My final goal is to use next export because the production server...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I need this feature too, I want to use http2 feature by passing options in
app.ts
coding in ESM.@jstayton So I’ve initially tested this behavior on TypeScript, and it worked, this was the reason I’ve commented.
But indeed, testing it on JavaScript, it doesn’t work.
I think it works on TypeScript because it eventually gets compiled to
commonjs
(Attempting to check the script type when using TypeScript inutil.js
atline 69
returnscommonjs
). Which is not the case when using ESM in JavaScript (it returnsmodule
).So, the reason this doesn’t work on
ESM
, is because the function used to load the file (line 85
instart.js
) loads only thedefault
export.https://github.com/fastify/fastify-cli/blob/dd476a793a637da367d278a5041395ef1b909949/util.js#L72-L74
@mcollina Please re-open this issue