-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
v0.10.2 appears to produce circular references where __commonJS
is not defined
#1070
Comments
UPDATE: Upon further debugging, it appears that this issue only comes up in v0.10.2, and appears to work fine in v0.10.0. |
isarray
isarray
Is it possible to provide a code sample that would allow me to reproduce the problem? |
Having difficulties reproducing in an isolated code sample, but have some more info from digging deeper. Two files are generated: index.js (sample from top of file) import {
DeveloperMode,
PrivateRoute,
ProvideAuth,
QueryClientProvider,
React,
Subscribable,
__commonJS,
__toModule,
_extends,
_inheritsLoose,
_objectWithoutPropertiesLoose,
// ... more app-specific dependencies
} from "/build/chunk-xyz";
// ../node_modules/isarray/index.js
var require_isarray = __commonJS((exports, module) => { // NOTE: this is where the error is thrown
module.exports = Array.isArray || function(arr) {
return Object.prototype.toString.call(arr) == "[object Array]";
};
}); chunk-xyz.js (sample from top of file) import {
Route,
define_BUILD_ENV_default,
useMutation
} from "/build//.//index.js";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
var __commonJS = (cb, mod) => () => (mod || cb((mod = {exports: {}}).exports, mod), mod.exports);
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, {get: all[name], enumerable: true});
}; If I'm understanding correctly, there's a possible circular reference here between index.js and chunk-xyz.js, so when index depends on |
isarray
__commonJS
is not defined
The bug here seems to be that a circular reference is generated in the first place. I believe one shouldn't ever be generated at all. The bug is presumably something to do with the Independent of that, this part of your reply also had me confused:
Is that true? If so, are you attempting to load
But the entry point |
I have a single entrypoint: entryPoints: ['./src/index.tsx'],
bundle: true,
splitting: true,
format: 'esm' that's loaded like so: <body>
<div id="app"></div>
<script src="build/index.js" type="module"></script>
</body> Within that entrypoint, I do make use of lazy loading to create chunks for routes that have large dependencies, like the Dashboard view that pulls in a charting library: (snippet simplified for the purposes of sharing—React Suspense is loaded properly here) import './styles/base.css';
const Dashboard = lazy(() => import('./modules/Dashboard'));
function App() {
return (
<Route path="/dashboard">
<Dashboard />
</Route>
);
} After esbuild runs, it generates all of these files:
Both |
One weird thing I'm noticing is simply changing the name of one of my global define variables removes it from the chunk In esbuild config: define: {
global: JSON.stringify({}),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__VERSION__: JSON.stringify(packageJson.version),
__COMMIT_HASH__: JSON.stringify(commitHash),
__BUILD_DATE__: JSON.stringify(new Date()),
__BUILD_ENV__: JSON.stringify(clientBuildEnv)
} Top of chunk: import {
Route,
define_BUILD_ENV_default,
useMutation
} from "/build//.//index.js"; And then top of chunk after renaming import {
Route,
useMutation
} from "/build//.//index.js"; |
EDIT: Spoke too soon. There was indeed a circular dependency in the code. |
It looks like v0.11.2 fixes the issue I was having on v0.10.2 with no code changes in the app. There's still a couple of imports at the top of |
This is likely a duplicate of #1081. |
Could you check again with version 0.11.5? I suspect that this issue will be resolved by the latest release. |
@evanw 0.11.5 works 👍 |
fwiw it worked in 0.11.2 as well |
Closing as it sounds like this has been fixed. |
This likely has to do with the breaking changes in v0.10.0,
No longer support module or exports in an ESM file
. I'm guessing at some point in the dependency chain there's anisarray
npm module being required and it has some problematic usage of module exports?The problem is I have no control over this particular dependency.
The text was updated successfully, but these errors were encountered: