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

Multipart Reader fails when compiled with error: ReferenceError: matchAfterPrefix is not defined #10187

Closed
vinc3m1 opened this issue Apr 14, 2021 · 5 comments
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)

Comments

@vinc3m1
Copy link

vinc3m1 commented Apr 14, 2021

from: #9620 (comment)

While #9620 was fixed for the --no-check case, the compile --unstable case is still broken using the test script linked to in #9620 (comment):

$ deno compile --unstable test.ts
[...]
Emit test
$ ./test
error: ReferenceError: matchAfterPrefix is not defined
    at scanUntilBoundary (file://$deno$/bundle.js:1702:9)
    at PartReader.read (file://$deno$/bundle.js:1737:22)
    at async copyN (file://$deno$/bundle.js:107:24)
    at async MultipartReader.readForm (file://$deno$/bundle.js:1825:27)
    at async file://$deno$/bundle.js:2095:18

But running with --no-check passes now so that's good:

$ deno run --no-check test.ts
entry [ "payload", "CONTENT" ]
formdata {
  file: [Function: file],
  value: [Function: value],
  entries: [GeneratorFunction: entries],
  removeAll: [AsyncFunction: removeAll],
  [Symbol(Symbol.iterator)]: [Function: [Symbol.iterator]]
}

test.ts:

import { MultipartReader } from "https://deno.land/std@0.93.0/mime/multipart.ts";
import { StringReader } from "https://deno.land/std@0.93.0/io/readers.ts";

// carriage returns added for running on POSIX, not needed if on windows
const content = `--------------------------366796e1c748a2fb\r
Content-Disposition: form-data; name="payload"\r
Content-Type: text/plain\r
\r
CONTENT\r
--------------------------366796e1c748a2fb--`

const boundary = "------------------------366796e1c748a2fb";

const stringReader = new StringReader(content);

const multipartReader = new MultipartReader(stringReader, boundary);
const formData = await multipartReader.readForm()
for (const entry of formData.entries()) {
  console.log("entry", entry);
}
console.log("formdata", formData);
@nayeemrmn
Copy link
Collaborator

What happens when you run on Deno 1.9.0 and std 0.93.0?

@vinc3m1
Copy link
Author

vinc3m1 commented Apr 14, 2021

What happens when you run on Deno 1.9.0 and std 0.93.0?

Just tested on deno 1.9.0 (release, aarch64-apple-darwin) and updated the test script to use std 0.93.0, still the same error output when compiled, just different line numbers.

@nayeemrmn
Copy link
Collaborator

cc @kdy1. Looks like the matchAfterPrefix() function is wrongly removed from https://deno.land/std@0.93.0/mime/multipart.ts during DCE when bundling the above code.

@kitsonk kitsonk added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Apr 14, 2021
@kdy1
Copy link

kdy1 commented Apr 14, 2021

I fixed it and published a new version :)

@satyarohith
Copy link
Member

This issue no longer exists with 1.9.2.

@kt3k kt3k closed this as completed Jul 30, 2021
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

No branches or pull requests

6 participants