node-oracledb icon indicating copy to clipboard operation
node-oracledb copied to clipboard

Error: Module not found: Can't resolve '@azure/app-configuration'

Open Dongw1126 opened this issue 1 year ago • 10 comments

  1. What versions are you using?
  • Node.js version
Node.js: 20.16.0
arch: x64
platform: win32
  • package version
next: "14.2.5"
oracledb: "^6.6.0"
  • database version
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production  
Version 19.24.0.1.0
  1. Is it an error or a hang or a crash?
    error

  2. What error(s) or behavior you are seeing?

Import trace for requested module:
./node_modules/oracledb/lib/configProviders/ sync ^\.\/.*$
./node_modules/oracledb/lib/oracledb.js
./node_modules/oracledb/index.js
./src/app/api/v1/test/route.js
 ⨯ ./node_modules/oracledb/lib/configProviders/azure.js:46:32
Module not found: Can't resolve '@azure/app-configuration'

https://nextjs.org/docs/messages/module-not-found
  1. Include a runnable Node.js script that shows the problem.

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.

// app/api/v1/test/route.js

export const dynamic = 'force-dynamic'

const oracledb = require('oracledb');

export async function GET() {
    return Response.json('Hello', { status: 200 })
}

test.zip

Dongw1126 avatar Aug 16 '24 05:08 Dongw1126

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

sharadraju avatar Aug 16 '24 05:08 sharadraju

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

sharadraju avatar Aug 16 '24 08:08 sharadraju

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?

Dongw1126 avatar Aug 16 '24 09:08 Dongw1126

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 .

sharadraju avatar Aug 16 '24 09:08 sharadraju

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.

Dongw1126 avatar Aug 16 '24 10:08 Dongw1126

Closing this issue for now. We will try to find a solution on this.

sharadraju avatar Aug 16 '24 12:08 sharadraju

@Dongw1126 Reopening this issue as I think I may have 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

configProviders.zip

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: image

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.

sharadraju avatar Aug 16 '24 13:08 sharadraju

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.

Dongw1126 avatar Aug 17 '24 04:08 Dongw1126

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.

sosoba avatar Aug 19 '24 05:08 sosoba

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.

sharadraju avatar Aug 20 '24 15:08 sharadraju

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

niels-k-86 avatar Aug 29 '24 13:08 niels-k-86

Closing this issue as there are workarounds and configuration changes available to solve the issue.

However we will look to actively move the config Providers related code as a plugin in the upcoming releases

sharadraju avatar Oct 16 '24 08:10 sharadraju

Thought I would mention another work around using turbopack since nextjs is mentioned in this issue and it doesn't have an externals config option.

experimental: {
    turbo: {
      resolveAlias: {
        '@azure/app-configuration': 'data:text/javascript,export default {};',
        '@azure/identity': 'data:text/javascript,export default {};',
        '@azure/keyvault-secrets': 'data:text/javascript,export default {};',
        'oci-common': 'data:text/javascript,export default {};',
        'oci-objectstorage': 'data:text/javascript,export default {};',
        'oci-secrets': 'data:text/javascript,export default {};',
      },
    },
  },

drollinger avatar Mar 28 '25 17:03 drollinger

@niels-k-86 @drollinger @sosoba A permanent fix is now available for this as we have moved all of the configuration store code to the plugins extension.

sharadraju avatar Jul 18 '25 14:07 sharadraju