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

Empty esmodules in dependencies cause ReferenceError: exports2 is not defined when building for node #910

Closed
airhorns opened this issue Mar 3, 2021 · 1 comment

Comments

@airhorns
Copy link

airhorns commented Mar 3, 2021

I am trying to bundle a module from npm (graphql-ws) that includes a file in it's tarball (node_modules/graphql-ws/lib/types.mjs) with these contents:


"use strict";
/**
 *
 * types
 *
 */
Object.defineProperty(exports, "__esModule", { value: true });

When I use esbuild to bundle a module that depends on this package, esbuild compiles it to:

// node_modules/graphql-ws/lib/types.mjs
var require_types = __commonJS(() => {
  __markAsModule(exports2);
});

which causes a reference error at runtime when trying to require the built module:

ReferenceError: exports2 is not defined
    at /Users/airhorns/Code/esbuild-test/build/test.js:622:18
    at /Users/airhorns/Code/esbuild-test/build/test.js:11:5
    at /Users/airhorns/Code/esbuild-test/build/test.js:648:17
    at /Users/airhorns/Code/esbuild-test/build/test.js:11:5
    at Object.<anonymous> (/Users/airhorns/Code/esbuild-test/build/test.js:7780:34)
    at Module._compile (node:internal/modules/cjs/loader:1091:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
    at Module.load (node:internal/modules/cjs/loader:971:32)
    at Function.Module._load (node:internal/modules/cjs/loader:812:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)

because the exports2 variable that's normally passed in to the module closure is not.

I am bundling with esbuild --bundle --target=es2017 --platform=node on v0.8.54. Here's a full reproduction where you can run yarn test to demonstrate the issue: https://github.com/airhorns/esbuild-empty-module-repro

The built code is just fine when not using --platform=node as well.

Thanks for any help you can give me!

@evanw evanw closed this as completed in 54ef111 Mar 3, 2021
@evanw
Copy link
Owner

evanw commented Mar 3, 2021

Thanks for the report. This problem should be fixed in the next release (not released yet).

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

Successfully merging a pull request may close this issue.

2 participants