Reputation: 53
I'm trying npm run dev in the cmd and it's throwing an error I've tried a lot of things but it doesn't seem to work.
Here is my package.json file:
{
"name": "project",
"version": "1.0.0",
"description": "project",
"main": "index.js",
"scripts": {
"dev": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"babel-polyfill": "^6.26.0"
}
}
Here is my wepack.config.js:
const path = require('path');
module.export = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'dist/js'),
filename: 'bundle.js'
},
mode: 'development'
};
I updated my npm, tried npm cache clean --force but and many other things but nothing seems to work. Please help.
This is the error I get:
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
Hash: c1735700111314ac598b
Version: webpack 4.43.0
Time: 62ms
Built at: 05/25/2020 1:24:29 PM
WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/
ERROR in Entry module not found: Error: Can't resolve './src' in 'C:\Users\usman\Desktop\coding\Forkify'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] dev: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\usman\AppData\Roaming\npm-cache\_logs\2020-05-25T08_24_29_792Z-debug.log.
Upvotes: 0
Views: 6491
Reputation: 53
I uninstalled webpack cli using PowerShell as administrator and installed it using PowerShell too, it worked perfectly for me. It is an administration problem so make sure to download cli using PowerShell. These were the commands that I used:
npm uninstall webpack webpack-cli
And for installation:
npm install webpack webpack-cli --save-dev
I hope I am being helpful. Thanks
Upvotes: 3
Reputation: 81
can you try to change your webpack.config.js like this :
const path = require("path");
module.exports = {
entry: "./src/js/index.js",
output: {
path: path.resolve(__dirname, "dist/js"),
filename: "bundle.js",
},
devServer: {
contentBase: path.resolve(__dirname, "dist"),
publicPath: "/js/",
},
};
and also modify the scripts object inside package.json file like below :
"scripts": {
"serve": "webpack-dev-server --mode development"
},
and finally run this command : npm run serve
Upvotes: 0