-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
[bug] default function in deno bundle is not a function #4055
Comments
I can't re-create this... Given an input of: export default function cubeIt(req: any, res: any) {
const result = 3*3*3;
res.send({ date: new Date(), result });
} I get an output of: // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// This is a specialised implementation of a System module loader.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let System;
let __inst;
(() => {
const mMap = new Map();
System = {
register(id, deps, f) {
mMap.set(id, {
id,
deps,
f,
exp: {}
});
}
};
const gC = (data, main) => {
const { id } = data;
return {
id,
import: async id => mMap.get(id)?.exp,
meta: { url: id, main }
};
};
const gE = data => {
const { exp } = data;
return (id, value) => {
const values = typeof id === "string" ? { [id]: value } : id;
for (const [id, value] of Object.entries(values)) {
Object.defineProperty(exp, id, {
value,
writable: true,
enumerable: true
});
}
};
};
const iQ = [];
const enq = ids => {
for (const id of ids) {
if (!iQ.includes(id)) {
const { deps } = mMap.get(id);
iQ.push(id);
enq(deps);
}
}
};
const dr = async main => {
const rQ = [];
let id;
while ((id = iQ.pop())) {
const m = mMap.get(id);
const { f } = m;
if (!f) {
return;
}
rQ.push([m.deps, f(gE(m), gC(m, id === main))]);
m.f = undefined;
}
let r;
while ((r = rQ.shift())) {
const [deps, { execute, setters }] = r;
for (let i = 0; i < deps.length; i++) setters[i](mMap.get(deps[i])?.exp);
const e = execute();
if (e) await e;
}
};
__inst = async id => {
System = undefined;
__inst = undefined;
enq([id]);
await dr(id);
return mMap.get(id)?.exp;
};
})();
System.register("exp_def", [], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
function cubeIt(req, res) {
const result = 3 * 3 * 3;
res.send({ date: new Date(), result });
}
exports_1("default", cubeIt);
return {
setters: [],
execute: function () {
}
};
});
const __exp = await __inst("exp_def");
export default __exp["default"]; Which when I then create another file that imports it: import fn from "./test.bundle.js";
console.log(fn); I get the following:
|
@kitsonk my bad, let me provide step by step guidance to reproduce, missing a second layer bundling |
clientCode.js
worker-fn.ts
bundler.ts
main.ts
|
|
Hmmmm... bundling bundles. We certainly didn't design for that. Is there a specific reason why you are bundling |
you'd see the following msg:
it's a known issue and hopefully it will be fixed with TS 3.8 take out await from generated bundled code of customerWorker.js |
you get this:
|
then rerun 2) and curl again
|
@kitsonk and here is the real problem ^^ bundling bundles worked fine in v0.32.0 before the rework from AMD to System |
I think bundling bundles is crazy personally... but hey, who am I to say. The problem is that bundles require TLA, because System is needed to support TLA, the problem is TypeScript 3.7 isn't able to support TLA, so effectively we can't bundle a bundle under TS 3.7, because bundles now need TLA. TS 3.8 just came out, which I am working on a PR right now, which should restore the functionality. |
@kitsonk thank you so much, you are amazing! |
Previously, bundles always utilised top level await, even if the bundled modules didn't require top level await. Now, analysis of the bundle is done and if none of the bundled modules are asynchronously executed, then the bundle as a whole will be synchronously executed. Fixes denoland#4055 Fixes denoland#4123
Previously, bundles always utilised top level await, even if the bundled modules didn't require top level await. Now, analysis of the bundle is done and if none of the bundled modules are asynchronously executed, then the bundle as a whole will be synchronously executed. Fixes denoland#4055 Fixes denoland#4123
v0.34.0
ERROR:
single function in the .js file to bundle:
works in v0.32.0 (System vs AMD for bundling)
@kitsonk the function identifier is no longer "file:///...", but doubt that change you have introduced yesterday has anything to do with described behavior, probably the offender is hiding here
The text was updated successfully, but these errors were encountered: