GithubHelp home page GithubHelp logo

Support native esm modules. about micro HOT 10 CLOSED

dbo avatar dbo commented on May 27, 2024 1
Support native esm modules.

from micro.

Comments (10)

leerob avatar leerob commented on May 27, 2024

#448

from micro.

dbo avatar dbo commented on May 27, 2024

@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.

from micro.

leerob avatar leerob commented on May 27, 2024

Would you be open to adding a PR with a test? Happy to review and merge it.

from micro.

pmbanugo avatar pmbanugo commented on May 27, 2024

@leerob What do you think about reopening this and solving it after we merge #458 ?

from micro.

leerob avatar leerob commented on May 27, 2024

Yeah I'm onboard.

from micro.

TooTallNate avatar TooTallNate commented on May 27, 2024

Why not just always use await import()?

from micro.

leerob avatar leerob commented on May 27, 2024

I'm good with that as well, especially since we're doing a major version bump.

from micro.

pmbanugo avatar pmbanugo commented on May 27, 2024

Since we're using TS now, that gets transpiled to using require statements. We already use await import

mod = await import(file);

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.

from micro.

electerious avatar electerious commented on May 27, 2024

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?

from micro.

pmbanugo avatar pmbanugo commented on May 27, 2024

@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.

from micro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.