Closed dbo closed 2 years ago
@leerob The patch I submitted supports esm in a much more complete way, looking up the package's type like node.js does instead of urging to use the .mjs extension. Please consider it.
Would you be open to adding a PR with a test? Happy to review and merge it.
@leerob What do you think about reopening this and solving it after we merge https://github.com/vercel/micro/pull/458 ?
Yeah I'm onboard.
Why not just always use await import()
?
I'm good with that as well, especially since we're doing a major version bump.
Since we're using TS now, that gets transpiled to using require
statements. We already use await import https://github.com/vercel/micro/blob/8d2ca07cea5f225752bf3e911e95cbf73caa3986/packages/micro/src/lib/handler.ts#L8
It was not a straightforward process to get that working the last time I tried. I plan to try a different solution when I get some time in the near future.
Is it correct that I currently can't use micro
together with an ES Module / "type": "module"
? Is there a recommended workaround or is it better to wait as this will be resolved soon?
@electerious If you're not using micro programmatically then the cli will fail when processing ESM files. If you want to use ESM, then you can use it this way:
//programmatic usage
const micro = require('micro')
const server = micro(async (req, res) => {
return 'Hello world'
})
server.listen(3000)
There would be a fix to load ESM files through the CLI in the near future.
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch
micro@9.3.4
for the project I'm working on.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.