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

Support ESM modules #267

Open
Eomm opened this issue Sep 6, 2020 · 5 comments
Open

Support ESM modules #267

Eomm opened this issue Sep 6, 2020 · 5 comments

Comments

@Eomm
Copy link
Member

@Eomm Eomm commented Sep 6, 2020

🚀 Feature Proposal

Support ESM module

Motivation

In the node14 the ESM modules will be no longer experimental

Example

// demo.mjs

import fs from 'fs'

export default function app (fastify, opts, next) {
  fastify.get('/', function (request, reply) {
    reply.send(fs.readFileSync('./package.json'))
  })

  next()
}

And then run it with fastify start demo.mjs

This feature should:

  • load the arg file as ESM when the file ends with mjs or the type in the package.json is module

The watching feature should be updated accordingly.

To support node10, it will be needed a --esm --no-esm flag because it doesn't support the type:module loading as node>=12 does

@mcollina
Copy link
Member

@mcollina mcollina commented Sep 6, 2020

For whoever takes this, https://github.com/fastify/fastify-autoload has all the necessary examples on how to load both cjs and mjs.

@danielglazer
Copy link

@danielglazer danielglazer commented Sep 28, 2020

Hi, can I grab this? looking for my first contribution @mcollina

@mcollina
Copy link
Member

@mcollina mcollina commented Sep 29, 2020

go for it!

@fox1t
Copy link
Member

@fox1t fox1t commented Sep 29, 2020

I would be happy to review that PR :)

@danielglazer
Copy link

@danielglazer danielglazer commented Oct 5, 2020

I am sorry but I see I would be fairly busy for the next month at least. if someone else would like to implement he/she should go for it...

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.