vercel / micro-dev

The development environment for `micro`
MIT License
705 stars 77 forks source link

Not compatible with `micro` v10.x #131

Open thinkverse opened 1 year ago

thinkverse commented 1 year ago

Currently micro-dev isn't compatible with micro v10.x, trying to use micro-dev with v10.x causes a MODULE_NOT_FOUND error. Seems micro v10.x dropped the lib directory used in previous versions, so micro-dev is requiring micro/lib and micro/lib/handler, which as of v10.x doesn't exist.

https://github.com/vercel/micro-dev/blob/718e5911bb2a1396740eb46fbe2796c22e57bdc7/lib/serve.js#L6-L7

Any chance micro-dev will get a v4 that supports micro v10.x?

leerob commented 1 year ago

Open to contributions 🙏

thinkverse commented 1 year ago

Open to contributions 🙏

Uno-reverse huh? 👀 Guess I'm tinkering with this then, feel free to assign me. 👍

flaming-codes commented 1 year ago

Adding my 2 cents, the micro-dev-package might be redundant with the built-in live reload feature w/ Node 18.

Specifically, you can use the --watch-flag to get an automated code reload on file changes.

Therefore, the following setup might be sufficient by leveraging the serve-function from the lib. Ofc this only works when you opt-out of the micro-command.

Node.js

18.12.1

package.json

{
  "scripts": {
    "dev": "node --watch index.js",
    "start": "node index.js",
  }
}

index.js

import 'dotenv/config';
import http from 'node:http';
import { send, serve } from 'micro';

const handler = async (req,res) => {
  // ...
};

const server = new http.Server(serve(handler));

server.listen(Number(process.env.PORT) || 8080);

I'm using such a setup in production for a small endpoint to generate OG-images at runtime: https://github.com/flaming-codes/crane-app/tree/main/services/og-img-gen