-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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] deno bundle generate broken code #4031
Comments
Your input file isn't being detected as a module... it is a "limitation" of TypeScript (or ECMAScript depending on how you see it) (see: microsoft/TypeScript#18232). Try this as your source file: console.log('Hello from Deno!');
export {}; It should resolve the issue. As far as the documents, I will raise a PR to update them. |
Actually, looking, the documents are accurate and don't represent the version you pasted in here. 😕 |
I was reading the readme from here console.log('Hello from Deno!');
export const myVar = 12 ; I am getting same error:
Generated bundle code: // 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("app", [], function (exports_1, context_1) {
"use strict";
var myVar;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
console.log('Hello from Deno!');
exports_1("myVar", myVar = 12);
}
};
});
const __exp = await __inst("file:///C:/Users/SOstad/Projects/tests/deno01/src/app");
export const myVar = __exp["myVar"]; |
It's the line or the line |
For the case #4031 (comment) the bundler shoud don't add I think it's two different bug! |
@bartlomieju we should remove the GitHub site on the repo (https://denoland.github.io/deno/) as it contains an old version of the website 😢. @IllusionPerdu you are right, the analysis we do when there is a single module is an additional problem, we get it wrong, we are "guessing" and we get it wrong. That needs to be fixed. Still before the export it was a different problem, but no, the |
@kitsonk Thanks for the notice - I've updated the gh-pages index.html |
Fixes denoland#4031 When a bundle contains a single module, we were incorrectly determining the module name, resulting in a non-functional bundle. This PR corrects that determination.
Fixes #4031 When a bundle contains a single module, we were incorrectly determining the module name, resulting in a non-functional bundle. This PR corrects that determination.
Hi 80.0.3987.116
I am using the latest Chrome (80.0.3987.116) and the top level await is still not supported in this version, So the bundle fails to load: Uncaught SyntaxError: Unexpected reserved word Top level await is still in stage 3 it seems: |
My personal opinion is that we don't hold up support top level await in bundles. We have been supporting it in Deno ever since it was implemented in V8 (and wanted to support it earlier). The only solution is that if the main module has no exports, we could drop the await, but it if does, we need to have the await there. @ry thoughts? |
@kitsonk I agree. I think if people are deploying the bundle to web they ought to just not use TLA... |
@ry, well the problem is they don't have a choice now, because the bundle loader works in an async way in order to accomodate bundling modules that require TLA, which means that we have to instantiate the loader using TLA. So until browsers support TLA, it means Deno bundles would not work in browsers. |
@kitsonk When i showed deno at my office one of the features we understood will be really useful for us was reuse of server module in the browser by just deno bundle them. |
While it might be complicated, I think I can detect when a bundle contains modules that are using TLA, and pass in something that will change the instantiation from async to sync. Let me see if I can do that. |
I tried to bundle a file with content code:
console.log('Hello from Deno!');
to bundle:
deno bundle app.ts bundle.js
it generated :
after I run it with
deno run bundle.js
here is the error:also Docs for bundle is outdated:
The text was updated successfully, but these errors were encountered: