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

fix: bundled wasm assets not found during build #681

Merged

Conversation

james-elicx
Copy link
Contributor

@james-elicx james-elicx commented Feb 26, 2024

This PR does the following:

  • Introduces some support for the filePathMap option in a function config file.
  • Symlinks assets to the function's folder, so that they can be found during the build process.

fixes #676
fixes #672

Example of this in a function's .vc-config.json:

image

Copy link

changeset-bot bot commented Feb 26, 2024

🦋 Changeset detected

Latest commit: 8849e15

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@cloudflare/next-on-pages Patch
eslint-plugin-next-on-pages Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 26, 2024

🧪 Prereleases are available for testing 🧪

@cloudflare/next-on-pages

You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/8116471634/npm-package-next-on-pages-681

@cloudflare/eslint-plugin-next-on-pages

You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/8116471634/npm-package-eslint-plugin-next-on-pages-681

@karthikjn01
Copy link

I've given this a test on my system, and it works! 🙌

@fineshop
Copy link

Thanks, wasm imports work as expected now.

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @james-elicx

I've seen this issue popup here and there and hadn't had the time to tackle it, thanks so much for having a look 🙏

But I am a bit hesitant on the changes for two reasons, one is the --skip-build flag issue I mentioned in my comment (should be an easy fix anyways) the other is that I am not sure if changing any file outside .vercel/static/output is appropriate...

I might be wrong but I think we don't do this anywhere else and try to keep things in memory instead whenever possible (to avoid issues like the one I mentioned in which using the skip build option can make the build no longer idempotent)

what do you think?

}

await mkdir(dirname(newAssetPath), { recursive: true });
await symlink(currentAssetPath, newAssetPath, 'file');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this breaks when using the -s|--skip-build flag:
Screenshot 2024-02-27 at 23 40 45

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good catch, adding a check to only do it when there is no file there.

@james-elicx
Copy link
Contributor Author

the other is that I am not sure if changing any file outside .vercel/static/output is appropriate...

I might be wrong but I think we don't do this anywhere else and try to keep things in memory instead whenever possible (to avoid issues like the one I mentioned in which using the skip build option can make the build no longer idempotent)

what do you think?

this is true. i dont think we do this anywhere else in the .vercel/output/functions. on the one hand, this make the fix a lot simpler, instead of changing how some of the deeper logic works, as it allows all the logic we have for the assets in a function's dir to continue doing their thing instead.

would you prefer i make the change to the deeper parts where it's processed instead of symlinking them?

@dario-piotrowicz
Copy link
Member

would you prefer i make the change to the deeper parts where it's processed instead of symlinking them?

yeah I think I'd much rather prefer that if it's not too much of a thing to ask 😓

I feel like if we start to "cheat" things can go out of hand and spiral out of control, saying "we never touch files that don't belong to us" feels like a much cleaner/clearer mental model that can prevent pain in the long run (and again, I think that adding exceptions to this can lead to unpredicability and pain 😓)

I don't think that not using symlinks is going to be problematic... it might a bit cumbersome as the paths need to be passed around though 😓

Would you be willing to give that a shot? 🙏
(if you prefer you can also do it in a separate branch and PR and we can compare that solution to this one)

@james-elicx
Copy link
Contributor Author

james-elicx commented Mar 1, 2024

Would you be willing to give that a shot? 🙏

There ya go. You were right, should have done it like this originally, good shout :)

Sorry for the delay!

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much, yeah now it looks perfect 😍

Sorry for the delay!

no problem at all 😄, thanks for the fix! 🙏

@dario-piotrowicz dario-piotrowicz merged commit 9b1d951 into cloudflare:main Mar 3, 2024
7 of 8 checks passed
@fineshop
Copy link

fineshop commented Mar 3, 2024

Thank you all for the fix! 🙂

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.

[🐛 Bug]: wasm imports don't work [🐛 Bug]: Unexpected error: ENOENT: no such file or directory
4 participants