awslabs / aws-crt-nodejs

NodeJS bindings for the AWS Common Runtime.
Apache License 2.0
38 stars 24 forks source link

Webpack build warning #438

Closed ChristopherGillis closed 1 year ago

ChristopherGillis commented 1 year ago

Repeatedly seeing this warning:

Warning: in ../../../node_modules/aws-crt/dist/native/binding.js 59:18-31
  Critical dependency: the request of a dependency is an expression
Screenshot 2023-03-23 at 11 56 08 AM

I see a related PR that is closed, but as of latest release, still seeing the error. https://github.com/awslabs/aws-crt-nodejs/pull/220

I have aws-crt@1.15.13 installed as a dependency of @aws-sdk/credential-provider-node@3.297.0

jmklix commented 1 year ago

What exactly are you trying to build? Is this warning preventing you from useing this dependency?

We have the browser samples working for aws-iot-device-sdk-js-v2 with webpack, so this should be working for you

unclejustin commented 1 year ago

I get the same warning building with NextJS.

FWIW the aws-crt still works this warning is just cluttering up the logs.

unclejustin commented 1 year ago

I am able to work around this issue by suppressing the warning as described here.

My updated next.config.js excerpt:

const webpack = require("webpack");

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config) => {
    config.plugins.push(
      new webpack.ContextReplacementPlugin(/\/aws-crt\//, (data) => {
        delete data.dependencies[0].critical;
        return data;
      })
    );
    return config;
  },
};

module.exports = nextConfig;
bretambrose commented 1 year ago

The native addon is loaded from a path computed dynamically based on the local host's architecture and OS properties. So on the surface this isn't something we can "fix."

You can suppress the warning using the solution above.

Another alternative is to use the browser distribution which does not need to load the native addon. In our browser samples, the redirection is found in the tsconfig: https://github.com/awslabs/aws-crt-nodejs/blob/main/samples/browser/http/tsconfig.json#L39-L41

The caveat about the browser implementation is that it does not contain Sigv4a support (AWS authentication that uses ECDSA signatures)