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

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

Closed
Dongw1126 opened this issue Aug 16, 2024 · 12 comments
Closed

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

Dongw1126 opened this issue Aug 16, 2024 · 12 comments

Comments

@Dongw1126
Copy link

  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 Dongw1126 added the bug label Aug 16, 2024
@sharadraju
Copy link
Member

sharadraju commented Aug 16, 2024

Hi @Dongw1126 Are you using any package bundlers like esbuild or webpack in your application?
If yes, please see #1688

@sharadraju
Copy link
Member

sharadraju commented Aug 16, 2024

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 #1688

@Dongw1126
Copy link
Author

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?

@sharadraju
Copy link
Member

sharadraju commented Aug 16, 2024

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 .

@Dongw1126
Copy link
Author

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.

@sharadraju
Copy link
Member

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

@sharadraju
Copy link
Member

sharadraju commented Aug 16, 2024

@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

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.

@Dongw1126
Copy link
Author

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.

@sosoba
Copy link

sosoba commented Aug 19, 2024

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.

@sharadraju
Copy link
Member

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.

@niels-k-86
Copy link

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

@sharadraju
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants