Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Error: Cannot resolve module

Tags:

I have created a simple project which uses babel and webpack. I have checked it in here

https://github.com/abhitechdojo/MovieLensReact.git

In my root folder I have two files script1.js and script2.js. My webpack.config.js looks like

module.exports = {     entry : {         main: [             'script1.js', 'script2.js'         ]     },     output : {         filename: 'public/main.js'     },     "module" : {         "loaders" : [             {                 "test": /\.jsx?/,                 "exclude": /node_modules/,                 loader: 'babel',                 query: {                     presets: ['es2015', 'react']                 }                            }         ]     } } 

but when I run webpack. it cannot find any javascript files

ERROR in multi main Module not found: Error: Cannot resolve module 'script1.js' in /Users/abhishek.srivastava/MyProjects/MovieLensReact  @ multi main  ERROR in multi main Module not found: Error: Cannot resolve module 'script2.js' in /Users/abhishek.srivastava/MyProjects/MovieLensReact  @ multi main 
like image 429
Knows Not Much Avatar asked Jan 23 '16 21:01

Knows Not Much


People also ask

What is module not found error in react JS?

A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies. The module you're trying to import is in a different directory. The module you're trying to import has a different casing.

Can't resolve Axios react JS?

To solve the error "Module not found: Error: Can't resolve 'axios'", make sure to install the axios package by opening your terminal in your project's root directory and running the command npm install axios and restart your development server.

How install react JS npm?

To install the full React toolchain on WSL, we recommend using create-react-app: Open a terminal(Windows Command Prompt or PowerShell). Create a new project folder: mkdir ReactProjects and enter that directory: cd ReactProjects . npx is the package runner used by npm to execute packages in place of a global install.

How do I import in react?

Now, importing is an operation that requires the permission of the module. Importing is possible only if the module or named property to be imported has been exported in its declaration. In React we use the keyword export to export a particular module or a named parameter or a combination.


1 Answers

In nodejs, when you call require("script1.js") it won't search in the current folder.

You have to use require("./script2.js"), to specify that the file is in the current folder.

In your case, modify the config file with main: ['./script1.js', './script2.js'].

like image 113
Pierre Emmanuel Lallemant Avatar answered Sep 21 '22 02:09

Pierre Emmanuel Lallemant