question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack and Typescript, v2.3.0 Error: Can't resolve 'react'

See original GitHub issue

I’m using Webpack 3 and Typescript, and I have been including instantsearch.js in my files like so:

import * as instantsearch from 'instantsearch.js';

This has been working fine.

I recently tried upgrading from 2.0.2 to 2.3.0 and I followed your es6 example in your v2 documentation:

import instantsearch from 'instantsearch.js/es';
import { searchBox } from 'instantsearch.js/es/widgets';
const search = instantsearch(/* parameters */);
search.addWidget(
    searchBox({
        container: '#search-input'
    })
);

However I am running into trouble. I get the following errors when I try initializing a widget.

ERROR in ./node_modules/instantsearch.js/es/components/MenuSelect.js
Module not found: Error: Can't resolve 'react' in 'C:\Users\mattucci\Documents\Visual-Studio-2017\Projects\Ontariocolleges\Ontariocolleges\node_modules\instantsearch.js\es\components'
 @ ./node_modules/instantsearch.js/es/components/MenuSelect.js 11:0-41
 @ ./node_modules/instantsearch.js/es/widgets/menu-select/menu-select.js
 @ ./node_modules/instantsearch.js/es/widgets/index.js
 @ ./Content/Scripts/search/search-programs-instantsearch.ts
 @ ./Content/Scripts/pages/program-search.ts

ERROR in ./node_modules/instantsearch.js/es/widgets/menu-select/menu-select.js
Module not found: Error: Can't resolve 'react' in 'C:\Users\mattucci\Documents\Visual-Studio-2017\Projects\Ontariocolleges\Ontariocolleges\node_modules\instantsearch.js\es\widgets\menu-select'
 @ ./node_modules/instantsearch.js/es/widgets/menu-select/menu-select.js 1:0-26
 @ ./node_modules/instantsearch.js/es/widgets/index.js
 @ ./Content/Scripts/search/search-programs-instantsearch.ts
 @ ./Content/Scripts/pages/program-search.ts

ERROR in ./node_modules/instantsearch.js/es/widgets/menu-select/menu-select.js
Module not found: Error: Can't resolve 'react-dom' in 'C:\Users\mattucci\Documents\Visual-Studio-2017\Projects\Ontariocolleges\Ontariocolleges\node_modules\instantsearch.js\es\widgets\menu-select'
 @ ./node_modules/instantsearch.js/es/widgets/menu-select/menu-select.js 2:0-33
 @ ./node_modules/instantsearch.js/es/widgets/index.js
 @ ./Content/Scripts/search/search-programs-instantsearch.ts
 @ ./Content/Scripts/pages/program-search.ts

What am I doing wrong in including the widget modules and why is it asking for react as a dependency? 😦

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
Giovanni-Mattuccicommented, Feb 14, 2018

@Haroenv @bobylito So I added the alias in webpack and now everything is working fine 👍

resolve: {
            extensions: ['.ts', '.js'],
            alias: {
                'react': 'preact-compat',
                'react-dom': 'preact-compat'
            }
}

@bobylito I never had the issue with 2.0.2, and it is only those two widgets the one widget MenuSelect that the error comes up for, which I am not using by the way. (update)

Oh and @Haroenv, sorry I can’t put up my code, I’m working with a private repo.

1reaction
Haroenvcommented, Feb 14, 2018

This should have been fixed since #2618. All references now point to preact-compat or preact in the code. Thanks for reminding us of this issue @Giovanni-Mattucci

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Module not found Can't resolve
My IDE resolves these interfaces fine but webpack always sends the following error. I tried different things but can't get that one to...
Read more >
How to fix 'Module not found: Can't resolve 'http' in ... - YouTube
Basically, just change ' react -scripts' to 4.0. 2 in your package.json and run `npm install` again :D Follow me on...
Read more >
React with Typescript and Webpack
In this guide, we will look at creating React app using Webpack and using TypeScript. The upside of this is greater control over...
Read more >
Resolve
Resolve. These options change how modules are resolved. Webpack provides reasonable defaults, but it is possible to change the resolving in detail.
Read more >
You may need an appropriate loader to handle this file type ...
config.ts file. One quick test would be to replace the small amount of typescript in your config file with webpack.config.js and see if ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found