opensearch-project / opensearch-js

Node.js Client for OpenSearch
https://opensearch.org/docs/latest/clients/javascript/
Apache License 2.0
189 stars 123 forks source link

[BUG] Import Issue version 3.0.0-beta.5: "Cannot find module '../api/_core/index" #851

Closed MichaelPooleLF closed 2 months ago

MichaelPooleLF commented 3 months ago

Describe the bug

Version 3.0.0-beta.5 of @opensearch-project/opensearch has an import error when building with webpack-cli version 1.5.4. Below is the error I received when attempting to build my project:

WARNING in ./node_modules/@opensearch-project/opensearch/api/utils.js 65:36-49 Critical dependency: the request of a dependency is an expression @ ./node_modules/@opensearch-project/opensearch/lib/OpenSearchAPI.js 18:32-55 @ ./node_modules/@opensearch-project/opensearch/lib/Client.js 49:22-48 @ ./node_modules/@opensearch-project/opensearch/index.js 32:19-42 @ ./src/services/getEsClient.ts 7:21-62 @ ./src/lambda/metricsGatherer.ts 10:22-56   WARNING in ./node_modules/@opensearch-project/opensearch/lib/OpenSearchAPI.js 28:26-39 Critical dependency: the request of a dependency is an expression @ ./node_modules/@opensearch-project/opensearch/lib/Client.js 49:22-48 @ ./node_modules/@opensearch-project/opensearch/index.js 32:19-42 @ ./src/services/getEsClient.ts 7:21-62 @ ./src/lambda/metricsGatherer.ts 10:22-56

Below is the error I received when attempting to execute code in an AWS Lambda:

{ "errorType": "Error", "errorMessage": "Cannot find module '../api/_core/index'", "code": "MODULE_NOT_FOUND", "stack": [ "Error: Cannot find module '../api/_core/index'", " at t (/var/task/app.js:2:268736)", " at E.index (/var/task/app.js:2:268342)", " at /var/task/app.js:2:511081", " at process.processTicksAndRejections (node:internal/process/task_queues:95:5)", " at async Promise.all (index 0)", " at async u.handler (/var/task/app.js:2:510307)" ] }

This error does not exist in @openseaerch-projejct/opensearch 2.11.0

Related component

Build

To Reproduce

This is not exact

  1. install latest beta version of @opensearch-project/opensearch
  2. install webpack and webpack-cli version 5.1.4
  3. Set up webpack
  4. attempt build

Expected behavior

build will compile with warning: Critical dependency: the request of a dependency is an expression

Additional Details

No response

dblock commented 3 months ago

Moving this to opensearch-js.

alihesari commented 3 months ago

I have the same problem with the search method in the latest version of Next.js API.

Error in API: Error: Cannot find module '../api/_core/search'

nhtruong commented 3 months ago

Investigating. I suspect that it's webpack's handling of lazy loading.

nhtruong commented 3 months ago

From what I've gathered, it's not possible to lazy load relative paths in webpack without turning client.indices.create() into (await client.indices).create() due to the use of async import() function. Lazy loading is just a nice-to-have feature in 3.0.0. We can get rid of it so the package works with Webpack and Next.js.

milmoul commented 3 months ago

We're having the same issue with esbuild, cf https://esbuild.github.io/api/#glob

nhtruong commented 3 months ago

Thanks everyone! 3.0.0-beta.6 has been released which removed lazy loading and every require() statement now uses literally string to help package managers like webpack grab all the needed files for bundling.

I've tested it locally with webpack, please lemme know if this version also resolves the issue for other frameworks as well.

dblock commented 2 months ago

This should be resolved, closing.