Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 103e46e

Browse files
Haroenvdhayab
andauthored
docs(example-ssr): use cjs imports (#3657)
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> **Summary** The example is ran using node without esm, and webpack also isn't set up for proper esm, so this errors in modern node (14+) if we use esm. Setting up for proper esm (type module etc) wouldn't be representative for most users, so we'll fall back to cjs CR-2214 <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? Are there any linked issues? --> **Result** <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. --> using cjs imports in hooks-ssr example Co-authored-by: Dhaya <154633+dhayab@users.noreply.github.com>
1 parent 596553c commit 103e46e

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

examples/hooks-ssr/.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
rules: {
3+
// this example is using CJS
4+
'no-restricted-imports': 'off'
5+
}
6+
}

examples/hooks-ssr/src/App.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ import {
1010
RefinementList,
1111
SearchBox,
1212
} from 'react-instantsearch-hooks-web';
13-
import { simple } from 'instantsearch.js/es/lib/stateMappings';
14-
import { history } from 'instantsearch.js/es/lib/routers';
13+
// because this is ran on node without type: "module" set in the package.json
14+
// we need to use commonjs instead of esm.
15+
// If you use ESM in Node, you can rely on these import statements instead:
16+
// import { simple } from 'instantsearch.js/es/lib/stateMappings';
17+
// import { history } from 'instantsearch.js/es/lib/routers';
18+
import { simple } from 'instantsearch.js/cjs/lib/stateMappings';
19+
import { history } from 'instantsearch.js/cjs/lib/routers';
1520

1621
import { searchClient } from './searchClient';
1722

0 commit comments

Comments
 (0)