zziger / esbuild-ifdef

Esbuild plugin adding preprocessor directives
MIT License
5 stars 1 forks source link

TypeError: ifdefPlugin is not a function #1

Open helm100 opened 1 year ago

helm100 commented 1 year ago

First of all, I'm extremely happy this plugin exists. It really extends the possibilities of building a client.

I could be wrong, but I think I stumbled upon a bug. My setup:

const esbuild = require("esbuild");
const ifdefPlugin = require("esbuild-ifdef");

esbuild.build({
    entryPoints: ["./app.ts"],
    bundle: true,
    outfile: "./out/bundle.js",
    minify: false,
    sourcemap: true,
    plugins: [
        ifdefPlugin({
            variables: {
                Client: "DESKTOP"
            },
            requireTripleSlash: false
        })
    ]
}).catch(() => process.exit(1));

I have esbuild v0.15.11 and esbuild-ifdef v0.2.0

Executing this code with node gives the error: TypeError: ifdefPlugin is not a function

This is fixed by changing the first line into const ifdefPlugin = require("esbuild-ifdef").default;

I'm not sure whether that is the expected behavior. I did not stumble upon it when searching the README.

zziger commented 1 year ago

Hi! I'll have a look at the this issue shortly, there's probably some problem with separating esmodules and commonjs versions in built package.