Skip to content

Is esbuild translating `const somelib = require("somelib"); into the appropriate ESM notation? #4459

Description

@eauchat

I had an issue with using underscore with esbuild, and reported it to underscore's issue tracker. But it seems the issue may be due to esbuild so I thought to bring back the issue here.
I'm not versed enough neither into underscore nor into esbuild to evaluate the situation, but from the nice and detailed explanations a maintainer of underscore gave me, I understand the following:

The following:

const _ = require("underscore");

may be translated to:

import * as _ from 'underscore';

by esbuild, while the expectation from underscore's maintainers is that it would be translated to:

import _ from 'underscore';

This causes some issues as outlined in this issue.
The detailed answer from @jgonggrijp also gives much more explanations and background.

I'm just making myself the messenger here, in case that would be a useful feedback for esbuild. But I'm aware that may be a voluntary choice for esbuild to behave this way. So feel free to close this issue if you don't find it relevant. The issue is not big and there are workarounds, so I wrote this issue just in case that's of any use for improving esbuild.
In any case thanks for the great tool :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions