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

[Turbopack] fail safe on binary import to string #75056

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

luwes
Copy link

@luwes luwes commented Jan 17, 2025

Related issue muxinc/next-video#266
Related discussion #72147

What?

This fixes an issue with Turbopack when importing binary files like image, videos.

Why?

Currently the build process will crash if Turbopack tries to convert a binary file import to a string.
For next-video this functionality is required though we don't use the binary content. It's more about the import path and file name.

example output:

Failed to compile

./videos/coblocks-ai.mp4.json.json
Code generation for chunk item errored
An error occurred while generating the chunk item [project]/videos/coblocks-ai.mp4.json.json (json)

Caused by:
- failed to convert rope into string
- invalid utf-8 sequence of 1 bytes from index 35

How?

This is a simple try / catch around the content to string conversion. If the conversion fails the content is set to an empty string for now. I considered converting to base64 so it could still be used in the JS Webpack loader but I have concerns that could slow down the build process too much.

In the future I hope Turbopack can support the Webpack "raw" option to pass the content as bytes.

@ijjk
Copy link
Member

ijjk commented Jan 17, 2025

Allow CI Workflow Run

  • approve CI run for commit: 72767a7

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

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

Successfully merging this pull request may close these issues.

2 participants