Open Dongw1126 opened 3 weeks ago
Hi @Dongw1126 Are you using any package bundlers like esbuild or webpack in your application? If yes, please see https://github.com/oracle/node-oracledb/issues/1688
Next.js seems to use webpack, which tries to load the Azure modules, even if it is conditionally required. This is the same issue as https://github.com/oracle/node-oracledb/issues/1688
Hi @Dongw1126 Are you using any package bundlers like esbuild or webpack in your application? If yes, please see #1688
Thanks for the quick reply.
I added "@azure/app-configuration": "^1.6.1"
as a dependency and the error doesn't occur anymore.
But wouldn't it be better to modify it so that it can run without having to install additional dependencies?
This is a webpack issue, where it does not ignore conditional requires. I will try to see if something can be done from our end to ensure that webpack can ignore them. See https://github.com/webpack/webpack/issues/8826 .
This is a webpack issue, where it does not ignore conditional requires. I will try to see if something can be done from our end to ensure that webpack can ignore them. See webpack/webpack#8826 .
Thank you.
If this is a duplicate issue, I think you can close it.
Closing this issue for now. We will try to find a solution on this.
@Dongw1126 Reopening this issue as I think I may found a temporary specific fix to work with frameworks like Next.js that use webpack. This is similar to the fix given in #1156. Here is how to apply the fix:
Unzip the attached configProviders.zip file to a new directory (D:\temp\configProviders)
Navigate to the application folder, where the node modules, including oracledb are installed (e.g., test/node_modules).
Navigate to the oracledb/lib folder.
Replace the configProviders directory in this directory with the new configProviders directory (i.e.,D:\temp\configProviders)
Remove the .next folder and rebuild the Next.js project again (npm run build).
Run npm run dev
Please try this fix and let me know.
I got the following output with http://localhost:3000/api/v1/test from your test.zip project after the fix:
PS: Please note that is a temporary and very specific fix tailored for your test case and the final fix (if it is possible from our end) still needs to be worked out.
As you mentioned, modifying node_modules works fine. No more errors.
However, modifying node_modules should be added to my CICD pipeline. Or I could use patch-package
.
Anyway, both of the solutions you mentioned work fine.
Thank you.
The ideal solution would be to move the Azure-enabled code into a separate package as a oracledb plugin and optionally include it in user project.
The ideal solution would be to move the Azure-enabled code into a separate package as a oracledb plugin and optionally include it in user project.
Thank you for the suggestion @sosoba. We will look into it.
You can set a custom Webpack config in NextJS. There you can mark packages as external. In your next.config.(m)js
file, do this:
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: config => {
/**
* These packages need to be added as external, else Oracle DB will try to load them due to a
* Webpack bug.
*
* See these two issues for more information:
* - https://github.com/oracle/node-oracledb/issues/1688
* - https://github.com/oracle/node-oracledb/issues/1691
**/
config.externals.push(
...[
"@azure/app-configuration",
"@azure/identity",
"@azure/keyvault-secrets",
"oci-common",
"oci-objectstorage",
"oci-secrets",
],
)
return config
},
}
export default nextConfig
package version
database version
Is it an error or a hang or a crash?
error
What error(s) or behavior you are seeing?
When I write the code below and call http://localhost:3000/api/v1/test,
I get "Module not found: Can't resolve '@azure/app-configuration'" error.
I haven't written any code related to azure and I'm getting an error even though I just added
require('oracledb')
. Please check this error.I've also attached the minimal executable code as a zip file.
test.zip