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

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

Closed
MichaelPooleLF opened this issue Aug 21, 2024 · 7 comments

Comments

@MichaelPooleLF
Copy link

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
Copy link
Member

dblock commented Aug 23, 2024

Moving this to opensearch-js.

@dblock dblock transferred this issue from opensearch-project/OpenSearch Aug 23, 2024
@alihesari
Copy link

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
Copy link
Collaborator

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

@nhtruong
Copy link
Collaborator

nhtruong commented Aug 26, 2024

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
Copy link

milmoul commented Aug 30, 2024

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

@nhtruong
Copy link
Collaborator

nhtruong commented Aug 30, 2024

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
Copy link
Member

dblock commented Sep 10, 2024

This should be resolved, closing.

@dblock dblock closed this as completed Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants