Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info

I am getting the error Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info. when I run the command npm run dev I also receive an error under this one that says ERROR in Entry module not found: Error: Can't resolve followed by a path. I am not too sure why it can't find an entry point any help would be greatly appreciated.

uploaded the whole project to github to help with visibilty. https://github.com/dustinm94/coding-challenge

webpack.config.js

  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
}

package.json

{
  "name": "coding_challenge",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development --watch ./coding/frontend/src/index.js --output ./coding/frontend/static/frontend/main.js",
    "build": "webpack --mode production ./coding/frontend/src/index.js --output ./coding/frontend/static/frontend/main.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.4.0",
    "@babel/preset-env": "^7.4.2",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.5",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0"
  },
  "dependencies": {
    "babel-preset-react": "^6.24.1",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6"
  }
}

.babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "plugins": ["transform-class-properties"]
}
like image 692
dmc94 Avatar asked Mar 31 '19 05:03

dmc94


2 Answers

I had this issue, and realised that the name webpack.config.js had a white space character in it.

enter image description here

like image 65
Hossein Margani Avatar answered Nov 09 '22 00:11

Hossein Margani


Fix for your issue is mentioned below

webpack.config.js and package.json will always be in your project basepath and node commands should be triggered from this path

You must make below corrections in your webpack.config.js & package.json

package.json

--watch will automatically look for the file specified in entry object in webpack.config.js and keep watching its dependency graph to autoreload on detecting changes. You need to update your package.json with below details

"scripts": {
    "webpack" : "webpack", // invoke this command from npm run dev & npm run build
    "dev": "npm run webpack -- --mode development --watch",
    "build": "npm run webpack -- --mode production"
}

Running in watch mode could lead to performance issues depending on the hardware you are using, read more about it

webpack.config.js

Add entry object to your webpack.config.js. If you didn't override entry object, by default, webpack points entry object to './src/index.js`. As you are not using default configuration in your project, webpack throws the error

ERROR in Entry module not found: Error: Can't resolve './src' in '/root/../coding_challenge'

To fix the error, you need to override the entry object with your target js file as shown below

module.exports = {
  entry : "./frontend/src/index.js",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
}

if above corrections are done,

npm run dev will run your project in watch mode

npm run build will generate production build for your project

Let me know if this info fixes your problem

like image 36
divine Avatar answered Nov 09 '22 00:11

divine