elastic / search-ui

Search UI. Libraries for the fast development of modern, engaging search experiences.
https://docs.elastic.co/search-ui
Apache License 2.0
1.92k stars 368 forks source link

Latest versions fail #1046

Closed avoinea closed 3 months ago

avoinea commented 6 months ago
Module not found: Error: Package path ./lib/cjs/helpers is not exported from package /app/node_modules/@elastic/search-ui (see exports field in /app/node_modules/@elastic/search-ui/package.json)
ModuleNotFoundError: Module not found: Error: Package path ./lib/cjs/helpers is not exported from package /app/node_modules/@elastic/search-ui (see exports field in /app/node_modules/@elastic/search-ui/package.json)
    at /app/node_modules/webpack/lib/Compilation.js:2016:28
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at /app/node_modules/neo-async/async.js:6883:13
    at /app/node_modules/webpack/lib/NormalModuleFactory.js:958:45
    at finishWithoutResolve (/app/node_modules/enhanced-resolve/lib/Resolver.js:567:11)
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:656:15
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at /app/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:89:43
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at /app/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:89:43
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at /app/node_modules/enhanced-resolve/lib/Resolver.js:714:5
    at eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /app/node_modules/enhanced-resolve/lib/DirectoryExistsPlugin.js:41:15
    at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
The command '/bin/sh -c yarn   && yarn build   && rm -rf /home/node/.cache   && rm -rf /home/node/.yarn   && rm -rf /home/node/.npm   && rm -rf /app/.yarn/cache' returned a non-zero code: 1
script returned exit code 1

Pinning version to 1.21.2 fixed the issue for me.

Samiul-TheSoccerFan commented 6 months ago

@avoinea : Thank you for letting us know. We will investigate and get back to you soon.

Samiul-TheSoccerFan commented 6 months ago

@avoinea : Can you provide more details on the error and/or how to reproduce the issue (preferably a link to Codesandbox)? I have successfully run a sample application with the latest version defined in here.

avoinea commented 6 months ago

@Samiul-TheSoccerFan https://github.com/eea/eea-website-frontend/tree/develop

Samiul-TheSoccerFan commented 6 months ago

@avoinea : We do not recommend importing directly from the files import { removeSingleFilterValue } from '@elastic/search-ui/lib/cjs/helpers';. It might create issues in the long run such as moving the interfaces or files into a different location.

gaving commented 5 months ago

Hi!

This has broken our build due to an automerge rule from our renovate tool.

Currently using search-ui-elasticsearch-connector like so:-

import APIConnector from "@elastic/search-ui-elasticsearch-connector";

According to https://docs.elastic.co/search-ui/api/connectors/elasticsearch

Resulting in:-

image

Has this import to be changed?

Concerned a patch semver change between 1.21.2 and 1.21.3 has knackered our build:-

https://github.com/elastic/search-ui/compare/v1.21.2...v1.21.3

We'll pin this on 1.21.2 for now!

joemcelroy commented 5 months ago

Hi there,

We recently introduced an update where we declared exports within the package json. (https://github.com/elastic/search-ui/pull/1043). We made this change as a patch as it should of been backwards compatible and was addressing a bug with it not able to be used by libraries which rely on ESM imports (https://github.com/elastic/search-ui/pull/1043).

However this change may have impacted those who bundlers that now using the exports path and having issues now with loading search-ui with ESM.

@gaving could you give me more context on your setup? How is your code bundled? nextjs / CRA etc. Will try replicate on my end.

Joe

gaving commented 5 months ago

Hi @joemcelroy -

Thanks for the quick response.

Nothing too complicated it seems to reproduce:-

❯ node --version
v18.19.1
npm i --save '@elastic/search-ui-elasticsearch-connector'

Add

"type": "module"

to package.json

index.js

import APIConnector from "@elastic/search-ui-elasticsearch-connector";
❯ node index.js
(node:20790) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/tmp/test_build/index.js:1
import APIConnector from "@elastic/search-ui-elasticsearch-connector";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1274:20)
    at Module._compile (node:internal/modules/cjs/loader:1320:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
    at node:internal/main/run_main_module:28:49

Node.js v18.19.1

Verified on Node 20.13.1 too for what it's worth.

joemcelroy commented 5 months ago

Thanks. Will follow what we did in Searchkit where the file extension is mjs.

joemcelroy commented 5 months ago

Update: This is becoming a little more difficult to do as now issue arises downstream due to searchkit not esm compatible yet. We are planning on removing searchkit as a dependency in the upcoming GAing.

For now use 1.20.1 @gaving - i dont want to create additional issues arising from making further changes. We will address this properly soon as we evaluate dependencies and ESM compatibility.

joemcelroy commented 5 months ago

@avoinea in 1.21.5, you can now access helpers via

import { ViewHelpers } from '@elastic/react-search-ui-views';

gaving commented 5 months ago

Update: This is becoming a little more difficult to do as now issue arises downstream due to searchkit not esm compatible yet. We are planning on removing searchkit as a dependency in the upcoming GAing.

For now use 1.20.1 @gaving - i dont want to create additional issues arising from making further changes. We will address this properly soon as we evaluate dependencies and ESM compatibility.

Funnily enough our CI just bumped, tested & merged 1.21.5 automatically? All appears good this side!

gaving commented 5 months ago

Ah sorry, disregard - that was @elastic/react-search-ui, the connector is still broke.

joemcelroy commented 5 months ago

just to highlight - this is an issue if you're using node directly, without a transpile step like typescript or vite. These transpilers handle different resolution strategies for dependencies so depending on your build setup, it may work fine.

botelastic[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

gaving commented 3 months ago

Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

This issue is still important to us!

gaving commented 4 weeks ago

Just to be clear, is this definitely a wontfix?

Running a server side service with:-

import APIConnector from "@elastic/search-ui-elasticsearch-connector";

Isn't possible to be run using node directly?

Just unsure if there's a suggested workaround is (i.e. without transpiling).