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

Inject not working with code splitting anymore #1086

Closed
Jarred-Sumner opened this issue Mar 30, 2021 · 1 comment
Closed

Inject not working with code splitting anymore #1086

Jarred-Sumner opened this issue Mar 30, 2021 · 1 comment

Comments

@Jarred-Sumner
Copy link
Contributor

Reproducible example: https://github.com/Jarred-Sumner/inject-repro

Run this:

rm -rf out; ./node_modules/.bin/esbuild 1.jsx 2.jsx  --outdir=out  --format=esm  --inject:inject.js  --bundle --define:"process.env.NODE_ENV=\"production\"" --splitting

Given > 1 similar file like this:

export function Greet() {
  return <div>hi</div>;
}

Greet();

It outputs a file like this:

import {
  React
} from "./chunk-ELFW36T7.js";

// 2.jsx
init_inject();
function Greet() {
  return /* @__PURE__ */ React.createElement("div", null, "hi");
}
Greet();
export {
  Greet
};

Notice how it's calling init_inject() but that function is not defined in the module? It's defined in the chunk being imported.

This is with inject.js set to the auto-import jsx example copy-pasted from the docs:

import * as React from 'react'
export { React }

Similar behavior occurs with variations of inject like:

export * from 'react';
export {default as React} from 'react';

If I had to guess, the problem is that React is being treated as a CJS module instead of an ESM, since it doesn't actually export ESM (UMD or CJS only)

@evanw
Copy link
Owner

evanw commented Mar 30, 2021

Thanks for the report. I'm currently investigating and working on a fix.

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