sdk icon indicating copy to clipboard operation
sdk copied to clipboard

NextJs build fails due to missing module for other platforms

Open felix9607 opened this issue 7 months ago • 0 comments

Hello,

I've created a NextJs App that uses the SDK via npm to retrieve secrets on the server side.

next.config.js:

const os = require('os');
module.exports = {
  webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
    config.module.rules.push({
      test: /\.node$/,
      use: [
        {
          loader: "nextjs-node-loader",
          options: {
            flags: os.constants.dlopen.RTLD_NOW,
            outputPath: config.output.path
          }
        },
      ],
    });
    return config;
  },
};

Infisical.js:

require("dotenv").config();
const { InfisicalClient } = require("@infisical/sdk");
const client = new InfisicalClient({
  siteUrl: "https://app.infisical.com", // Optional, defaults to https://app.infisical.com
  auth: {
    universalAuth: {
      clientId: process.env.INFISICAL_CLIENT_ID,
      clientSecret: process.env.INFISICAL_CLIENT_SECRET,
    },
  },
});

module.exports = {
  async getSecret(key) {
    const { secretValue } = await client.getSecret({
      environment: process.env.NODE_ENV === "production" ? "prod" : "dev",
      projectId: "<PROJECT_ID>",
      path: "/",
      type: "shared",
      secretName: key,
    });
    return secretValue;
  },
};

Running the App via npm run dev works fine but when I try to run a build with npm run build it fails with several errors like for all different platforms that are missing their sdk since npm only installs the one for mac in my case:

./node_modules/@infisical/sdk/binding.js
Module not found: Can't resolve './infisical.android-arm64.node' in '/<PATH>/node_modules/@infisical/sdk'

Import trace for requested module:
./node_modules/@infisical/sdk/binding.js
./node_modules/@infisical/sdk/lib/infisical_client/index.js
./node_modules/@infisical/sdk/lib/index.js
./utils/Infisical.js
./app/api/services/funding/route.js

felix9607 avatar Jul 15 '24 13:07 felix9607