Skip to content

Deno bundle doesn't include the dependencies properly #5610

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

Closed
youknowriad opened this issue May 18, 2020 · 10 comments
Closed

Deno bundle doesn't include the dependencies properly #5610

youknowriad opened this issue May 18, 2020 · 10 comments

Comments

@youknowriad
Copy link

Hi there! and thanks for your amazing work on Deno.

I have the following code

import { createElement } from 'https://cdn.pika.dev/[email protected]';
import { render }  from 'https://cdn.pika.dev/[email protected]';

const el = createElement;

export function run() {
    render(
        el( 'div', {}, 'Hello!' ),
        document.querySelector('#root')
    );
}

an my (maybe wrong) assumption is that running deno bundle index.js index.bundle.js would give a single JS file including my code and its deps that I could load in an HTML module using a script module tag but the result doesn't embed my deps at the moment (causing JS errors).

So I'm wondering:

  • Is my assumption wrong and the command not supposed to work this way?
  • Are my deps not compatible?
  • something else...

Thanks

@kitsonk
Copy link
Contributor

kitsonk commented May 18, 2020

Need to look into it a bit more to say one way or another...

@devvaneio
Copy link

@youknowriad, look at these issues: #3799, #3726 and this
PR that was merged #3863

@kitsonk
Copy link
Contributor

kitsonk commented May 19, 2020

@lusatiro I don't think those issues and that PR has anything to do with this issue, especially since I created one of those issues and the PR you mentioned. :-D

@devvaneio
Copy link

devvaneio commented May 19, 2020

@kitsonk, I'm not telling that these issues and PR solves the problem.
I know that it was you, I'm watching the threads. I'm just trying to give more context.
This works for me:

// x.ts
import { createElement } from 'https://cdn.pika.dev/[email protected]';
import { render } from 'https://cdn.pika.dev/[email protected]';

const el = createElement;

export function run() {
  render(
    el( 'div', {}, 'Hello!' ),
      document.querySelector('#root')
   );
}
// y.ts
const [errors, emitted] = await Deno.compile("./x.ts", undefined, {
  lib: ["dom", "esnext"],
});

const truncate_filename = (filename: string) => filename.replace('file:///', '');

for (const [filename, text] of Object.entries(emitted)) {
  console.log(${truncate_filename(filename)});
  console.log(text.split('\n').map(line => \t${line}).join('\n'));
}

Idk if it is the right approach so would be great know from you @kitsonk the right way!

@devvaneio
Copy link

devvaneio commented May 19, 2020

The approach used by @youknowriad result on:

error: Uncaught AssertionError: Assertion failed.
    at Object.assert ($deno$/util.ts:33:11)
    at compile ($deno$/compiler.ts:1355:5)
    at async tsCompilerOnMessage ($deno$/compiler.ts:1548:22)
    at async workerMessageRecvCallback ($deno$/runtime_worker.ts:73:9)

This is not a very informative error e should be improved of course.
But I believe that this (error on code from @youknowriad) was caused by the missing types from DOM

@kitsonk
Copy link
Contributor

kitsonk commented May 19, 2020

Yeah, I had missed that it would have required lib dom. Thanks for pointing that out. I was just getting fixated that remote code wasn't being included, as the OP wasn't indicating he was getting any errors.

And yes, deno bundle only is intended to really work for bundling workloads for Deno. If you are trying to create a bundle to run in a browser (or possibly Deno), using the Deno.bundle() API is what you should do, supplying the proper libs.

@gensior
Copy link

gensior commented May 19, 2020

Where can I find documentation on the Deno.bundle() API?

@cknight
Copy link
Contributor

cknight commented May 19, 2020

@gensior the bundle() API is currently behind the unstable flag. Docs can be found at https://github.com/denoland/deno/blob/master/cli/js/lib.deno.unstable.d.ts#L648

@gensior
Copy link

gensior commented May 19, 2020

@cknight thanks!

@youknowriad
Copy link
Author

Thanks a lot of your answers, I'm closing this issue now. Feel free to reopen if there's anything left to consider here.

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

No branches or pull requests

5 participants