fastify-vite icon indicating copy to clipboard operation
fastify-vite copied to clipboard

Compile server dist file to mjs instead of cjs

Open davidmeirlevy opened this issue 4 years ago • 0 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

compile the server app into mjs file instead of cjs.

Motivation

mjs has top-level await like the browser also has, and it's much more consistent.

Example

When I ran the app on dev mode, I managed to write a line like await import("my-third-party-dep") on a file's top-level, but this line failed to compile (the build failed).

When I tried to use something like:

// this all area is removed from the client dist anyway:
if(import.meta.env.SSR) {
  require("my-third-party-dep")  
}

It didn't run for both dev and build, with the error: ReferenceError: require is not defined

davidmeirlevy avatar Nov 26 '21 19:11 davidmeirlevy