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

[bundle] Bundled code doesn't work as expected #8770

Closed
MariusVatasoiu opened this issue Dec 15, 2020 · 12 comments · Fixed by #8901
Closed

[bundle] Bundled code doesn't work as expected #8770

MariusVatasoiu opened this issue Dec 15, 2020 · 12 comments · Fixed by #8901
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)

Comments

@MariusVatasoiu
Copy link

MariusVatasoiu commented Dec 15, 2020

Code bundled with deno bundle works different than deno run.

Steps to reproduce it:

This code works:

import { resize } from 'https://deno.land/x/[email protected]/mod.ts';

const portraitJPG = await resize(Deno.readFileSync("./portrait.jpg"), {width: 100});
Deno.writeFileSync('./portrait.small.jpg', portraitJPG);

But this code doesn't:

deno bundle https://deno.land/x/[email protected]/mod.ts index.bundle.js
import { resize } from './index.bundle.js';

const portraitJPG = await resize(Deno.readFileSync("./portrait.jpg"), {width: 100});
Deno.writeFileSync('./portrait.small.jpg', portraitJPG);

Expected result:

resize function should return an Uint8Arrray for the resized image and than should be written on the disk.

Actual result:

error: Uncaught Error: unknown JPEG marker f980
                        throw new Error("unknown JPEG marker " + fileMarker.toString(16));
                              ^
    at constructor.parse (file:///.../index.bundle.js:1155:31)

Deno version: 1.6.1

I used this image but should work with any .jpg file.

@kitsonk
Copy link
Contributor

kitsonk commented Dec 15, 2020

When you say "doesn't work" what happens?

What version of Deno?

@kitsonk kitsonk added the needs info needs further information to be properly triaged label Dec 15, 2020
@MariusVatasoiu
Copy link
Author

@kitsonk I updated the issue with the error and Deno version.

@Nexxkinn
Copy link

Nexxkinn commented Dec 15, 2020

Might be caused by deno messing up code execution order.

In my current version ( 1.6.0 ). This line of code in my repo:

// using oak framework
const app = new Application();
      app.use(router.routes());
      app.use(router.allowedMethods());

      app.addEventListener("listen", (ctx) => {
          console.log(`Serving requests at ${ctx.hostname}:${ctx.port}`)
      })
await app.listen( {hostname:config.hostname,port:config.port} )

will be bundled like this

const app2 = new Application();
app2.addEventListener("listen", (ctx)=>{
    console.log(`Serving requests at ${ctx.hostname}:${ctx.port}`);
});
await app2.listen({
    hostname: config.hostname,
    port: config.port
});

// some hundreds of lines later
app2.use(router.routes());
app2.use(router.allowedMethods());

causing an error like this:

error: Uncaught (in promise) TypeError: There is no middleware to process requests.
            throw new TypeError("There is no middleware to process requests.");
                  ^
    at Application.listen (file:///C:/Users/natha/Desktop/repos/downhost/dist/downhost.js:13102:19)
    at file:///C:/Users/natha/Desktop/repos/downhost/dist/downhost.js:13161:12

My solution would be not to bundling the module until deno fix this issue in future versions.

@FrageDev
Copy link

FrageDev commented Dec 15, 2020

I've got the same problem as @Nexxkinn . I'm developing an API using oak with Deno 1.6.1 by using Typescript.
My API is working without any error (as far as I know) when I start it with deno run --allow-all app.ts
When I use deno compile app.ts and I start the app.exe I've got :

>app error: TypeError: There is no middleware to process requests. at Application.listen (file://$deno$/bundle.js:10697:19) at file://$deno$/bundle.js:10753:12

Seems bundle and compile has the same issue ?

@kitsonk kitsonk added needs investigation requires further investigation before determining if it is an issue or not swc related to swc (bundling/transpiling) and removed needs info needs further information to be properly triaged labels Dec 15, 2020
@kitsonk
Copy link
Contributor

kitsonk commented Dec 15, 2020

cc/ @kdy1

@kdy1
Copy link

kdy1 commented Dec 15, 2020

@kitsonk I'm now working to fix this issue. (Preserving order of statements within single module would be solution to this issue.)

Exam is over :)
Sorry for the delay.

@kitsonk kitsonk added bug Something isn't working correctly and removed needs investigation requires further investigation before determining if it is an issue or not labels Dec 15, 2020
@kitsonk
Copy link
Contributor

kitsonk commented Dec 15, 2020

No problem! 😁 Hopefully the exams went well!

@kdy1
Copy link

kdy1 commented Dec 27, 2020

I think this is fixed by swc-project/swc#1264

@Nexxkinn
Copy link

Looking forward for this fix, thank you very much @kdy1 !

kdy1 added a commit to kdy1/swc that referenced this issue Dec 27, 2020
@kdy1
Copy link

kdy1 commented Dec 27, 2020

This is fixed by new version of swc_bundler. (I've added test for it)

@MariusVatasoiu
Copy link
Author

I still have this problem with Deno 1.6.3.

@ry
Copy link
Member

ry commented Jan 13, 2021

This will be fixed in 1.7.0 which will be released next week, January 19th.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants