aws / aws-iot-device-sdk-js-v2

Next generation AWS IoT Client SDK for Node.js using the AWS Common Runtime
Apache License 2.0
214 stars 96 forks source link

Error: AWS CRT binary not present in any of the following locations on Nextjs app running npm run dev #496

Open prakashmallow opened 2 months ago

prakashmallow commented 2 months ago

Describe the bug

I facing an issue while installing the aws-iot-device-sdk-v2 package. After importing iot and mqtt, I attempt to run the Next.js app using npm run dev but encounter the below errors

Error: AWS CRT binary not present in any of the following locations:
        /bin/darwin-arm64-cruntime/aws-crt-nodejs.node
    at eval (webpack-internal:///./node_modules/aws-crt/dist/native/binding.js:110:11)

- error node_modules/aws-crt/dist/native/binding.js (109:0) @ eval
- error Error: AWS CRT binary not present in any of the following locations:
        /bin/darwin-arm64-cruntime/aws-crt-nodejs.node
    at eval (webpack-internal:///./node_modules/aws-crt/dist/native/binding.js:110:11)

Expected Behavior

After importing iot and 'mqttfromaws-iot-device-sdk-v2` the nextjs app running as we expect normally

Current Behavior

Currently, it's throwing the below error we can import { it, mqtt } from 'aws-iot-device-sdk-v2' on the Nextjs app component and run on it.

Error: AWS CRT binary not present in any of the following locations:
        /bin/darwin-arm64-cruntime/aws-crt-nodejs.node
    at eval (webpack-internal:///./node_modules/aws-crt/dist/native/binding.js:110:11)

- error node_modules/aws-crt/dist/native/binding.js (109:0) @ eval
- error Error: AWS CRT binary not present in any of the following locations:
        /bin/darwin-arm64-cruntime/aws-crt-nodejs.node
    at eval (webpack-internal:///./node_modules/aws-crt/dist/native/binding.js:110:11)

Reproduction Steps

  1. Install aws-iot-device-sdk-v2 on the Nextjs app.
  2. import iot and mqtt from 'aws-iot-device-sdk-v2 and iot and mqtt APIs are used on the Nextjs app component.
  3. run npm run dev on terminal
  4. the above-mentioned mention error throwing on the terminal

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.19.5

Environment details (OS name and version, etc.)

| Environment | version | | macOS | 14.4.1 | | processer | m1 chip | | node 20.12.1 | | nextjs | 13.4.7 |

hari-prasad-a commented 2 months ago

Facing same issue

I am also facing the same issue with aws-iot-device-sdk-v2 package. When I import iot and mqtt in an Next.js application and while running the app below error is thrown.

Error: AWS CRT binary not present in any of the following locations:
        /bin/darwin-arm64-cruntime/aws-crt-nodejs.node
    at eval (webpack-internal:///./node_modules/aws-crt/dist/native/binding.js:110:11)
jmklix commented 2 months ago

I'm looking into this, and I think part of the problem is that you are trying to use the node functions of this sdk rather than the browser functions. You can fix this by adding the browser path to your tsconfig.json:

"paths": {
      "aws-iot-device-sdk-v2": ["./node_modules/aws-iot-device-sdk-v2/dist/browser"]
    }

I'm still getting some other errors when trying to run the pub_sub_mqtt5 inside a next.js app, so I'm still looking into this.

prakashmallow commented 2 months ago

@jmklix My Next.js app is running with JSX components instead of TSX. I'm encountering an issue where the @module-federation/nextjs-mf npm package is causing problems. When I remove the @module-federation/nextjs-mf npm package from my app, it works fine with aws-iot-device-sdk-v2. However, my application requires the @module-federation/nextjs-mf npm package

Ref: https://github.com/module-federation/core/issues/2462

xiazhvera commented 2 months ago

I think Next.js allows you to specify the library paths through jsconfig.json. Reference: https://nextjs.org/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases

prakashmallow commented 2 months ago

@xiazhvera @jmklix After applying the changes mentioned in the jsconfig.json file, I'm still encountering the same issue.

jmklix commented 2 months ago

Can you provide more detailed steps for setting up nextjs app?

I can get the next.js getting started app working when I combine it with the pub_sub_mqtt5 sample from this repo, while making only a few minor changes. I can also provide more detailed steps on how I set that up if you would like (it's in TS not JS).

prakashmallow commented 2 months ago

@jmklix

https://github.com/hari-prasad-a/mqtt-container-app https://github.com/hari-prasad-a/mqtt-child-app

Please clone the above repositories with all the settings already completed for the Next.js apps. Follow the below steps:

  1. Install packages on both repositories.
  2. First, run mqtt-child-app.
  3. After successfully running mqtt-child-app, proceed to start mqtt-container-app.
prakashmallow commented 1 month ago

@jmklix Please check this comment and give guidances for how to configure aws-iot-device-sdk-v2 on webpack config.externals on Nextjs app

prakashmallow commented 1 month ago

@jmklix any update?

xiazhvera commented 1 month ago

It seems like the issue more related to a webpack configuration rather than a problem with our SDK. I'm not positive if we would have a good solution for it. Unfortunately, I'm a bit short to dive deeper into it right now. I'll be able to revisit the issue in two weeks.

xiazhvera commented 1 month ago

I made several attempts to fix the issue following the suggestions mentioned in module-federation, but unfortunately, I wasn't able to resolve it. Currently, I don't have a viable solution for this problem. I'll leave the issue open in case anyone has further updates or suggestions.

blakeage commented 2 weeks ago

I don't think this is isolated to NextJS. I'm using Webpack 5.92.0 to package up a module, running on OS X Sonoma 14.5, with Node 16.16.0. Importing a module from aws-iot-device-sdk-js-v2 seems be what initiates the issue.

The problem seems to be in how a path is loaded in aws-crt. Here's a Webpack build warning that seems related:

WARNING in ./node_modules/aws-crt/dist/native/**binding.js 104**:18-31
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/aws-crt/dist/native/auth.js 20:34-54
 @ ./node_modules/aws-crt/dist/index.js 42:26-50
 @ ./node_modules/aws-iot-device-sdk-v2/dist/index.js 53:18-36
 @ ./main.js 1:0-44

I've attached a very basic project that also shows the issue: aws-crt-problem.zip

prakashmallow commented 2 weeks ago

@xiazhvera @jmklix Any update on this issue? I have more dependencies with this AWS IoT package. When will this issue be fixed, or can we look for an AWS IoT alternative?