-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
libraries using __dirname
don't resolve correctly in server components
#49783
Comments
In the case you're using typescript you probably don't have the esModuleInterop enabled. Could you check if this fixes your issue by chance? https://www.typescriptlang.org/tsconfig#esModuleInterop |
@JesseKoldewijn we do already have that in our tsconfig
|
Does do you yourself give it a path or does it do this internally in the package itself? |
Alright check! Could you maybe try the following. In your Next.js config, add the "@emurgo/cardano-serialization-lib-nodejs" to the "experimantal" config entry "serverComponentsExternalPackages" to check if it still throws this same error when added to this config option. |
Ah i see, didn't know that was an option. That does appear to be working after altering the reproduction. I will try in our production app and see if its working there as well. |
@JesseKoldewijn I can confirm adding the libraries to |
I'll open a PR tomorrow that fixes this issue in the future👌 |
@mPaella did you only add the package in question to that config entry or also wasm-pack? |
I went with this
|
@mPaella just submitted the PR ;) So if everything goes smoothly you'll be able to run your project on the canary release after this PR gets merged without the before mentioned config entry 👍 |
Awesome! Would love to know what the longer term solution here is as well. What's the difference in compilation that's causing these packages to be added to the exclusions list? What can libraries do to avoid this? |
As far as I know it has to do with how the App Router is compiled. As for how to prevent this, not sure. Haven't dug that deep into it to be honest. Plus I personally haven't ran into a package in the projects that I work on where they run into these compile issue. I mainly recognized this behavior because bcrypt also used to have issues in the App Router before I PR'ed it into this external package list. ;) But, I'm going to move to a Next.js focused job soon so I'm sure I'll be of more used by that time with regards to more deep stuff than just these small fixes which are just pattern recognition in my mind right now. |
@mPaella btw, can you keep this issue open by chance till its fixed upstream without the experimental manual config? |
The PR unfortunately is still open in review (just synced it with upstream to make merging for the core team easier). So keep an eye on PR #49938 I would expect it can be merged soon since its just a two-line addition. |
…ackages to prevent issue #49783 from happening. (#49938) fixes #49783 ### What? Added the following packages to the server component exclusion list which prevents these packages from going through the currently default compile pipeline for apps that use the App Router. Packages added are: "@blockfrost/blockfrost-js", "@jpg-store/lucid-cardano" and "mongoose". (For instance, mongo was already in this exclusion list) ### Why? These packages are required by the "@emurgo/cardano-serialization-lib-nodejs" packages and break when not added to this list while using the app router. ### How? I've added these packages to the server-external-packages json file in the Next.js package's lib directory.
@mPaella the fix for your issue just got merged. So make sure to bump your project to the next canary release (as in, the next release from this moment) to be able to run your project without the before mentioned manual experimental config👌 Edit: just checked real quick and it's already pushed into the latest canary release🤙 |
…ackages to prevent issue vercel#49783 from happening. (vercel#49938) fixes vercel#49783 ### What? Added the following packages to the server component exclusion list which prevents these packages from going through the currently default compile pipeline for apps that use the App Router. Packages added are: "@blockfrost/blockfrost-js", "@jpg-store/lucid-cardano" and "mongoose". (For instance, mongo was already in this exclusion list) ### Why? These packages are required by the "@emurgo/cardano-serialization-lib-nodejs" packages and break when not added to this list while using the app router. ### How? I've added these packages to the server-external-packages json file in the Next.js package's lib directory.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/gifted-einstein-mo56ss?file=%2Fnext.config.js%3A19%2C7
To Reproduce
/
. See that the page loads/foo
. See that the page errors, due to incorrectly deriving the path to the WASM fileDescribe the Bug
The reproduction uses a library, @emurgo/cardano-sererialization-lib that's compiled with wasm-pack. Wasm-pack saves the .WASM file, and loads it by deriving the path using this compiled code:
As a hack to see if i could fix it, I edited the compiled lib to use this, which works correctly:
Expected Behavior
I expect it to "just work" in both the
app
andpages
directoryThis issue could be fixed by the underlying libraries like wasm-pack, and I originally opened an issue there, but it seems like this may be a larger problem with nextjs itself
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: