admin管理员组文章数量:1391968
I am new to React.js and i am trying to setup simple react application locally using webpack. while running the npm run dev mand i m getting below error.
Error getting in mand prompt after running npm run dev
F:\ReactApp\react-webpack>npm run dev
> [email protected] dev F:\ReactApp\react-webpack
> webpack -wd
error: option '-d, --devtool <value>' argument missing
npm ERR! code ELIFECCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `webpack -wd`
npm ERR! Exit status 1
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 plete log of this run can be found in:
npm ERR! C:\Users\nilesh\AppData\Roaming\npm-cache\_logs\2020-10-30T08_33_31
_702Z-debug.log
Below is code in package.json file
{
"name": "react-webpack",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"webpack": "^5.3.2",
"webpack-cli": "^4.1.0"
},
"devDependencies": {},
"scripts": {
"dev": "webpack -wd"
},
"author": "",
"license": "ISC"
}
Below is code for the webpack.config.js file
const path = require('path');
module.exports = {
entry : './js/app.js',
output : {
path: path.join(__dirname,'public'),
filename: 'bundle.js'
},
module :{
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader:'babel-loader'
}
]
}
};
Code in app.js file
import React from "react";
import ReactDOM from "react-dom";
class HelloMessage extends React.Component {
render() {
return (
<div>
Hello {this.props.name}
</div>
);
}
}
ReactDOM.render(
<HelloMessage name="Taylor" />,
document.getElementById('root')
);
Here my .babelrc file
{
"presets":[
"react",
"es2015"
]
}
I have already install latest version of node.js
Thanks in Advance
Nilesh Kulkarni
I am new to React.js and i am trying to setup simple react application locally using webpack. while running the npm run dev mand i m getting below error.
Error getting in mand prompt after running npm run dev
F:\ReactApp\react-webpack>npm run dev
> [email protected] dev F:\ReactApp\react-webpack
> webpack -wd
error: option '-d, --devtool <value>' argument missing
npm ERR! code ELIFECCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `webpack -wd`
npm ERR! Exit status 1
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 plete log of this run can be found in:
npm ERR! C:\Users\nilesh\AppData\Roaming\npm-cache\_logs\2020-10-30T08_33_31
_702Z-debug.log
Below is code in package.json file
{
"name": "react-webpack",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"webpack": "^5.3.2",
"webpack-cli": "^4.1.0"
},
"devDependencies": {},
"scripts": {
"dev": "webpack -wd"
},
"author": "",
"license": "ISC"
}
Below is code for the webpack.config.js file
const path = require('path');
module.exports = {
entry : './js/app.js',
output : {
path: path.join(__dirname,'public'),
filename: 'bundle.js'
},
module :{
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader:'babel-loader'
}
]
}
};
Code in app.js file
import React from "react";
import ReactDOM from "react-dom";
class HelloMessage extends React.Component {
render() {
return (
<div>
Hello {this.props.name}
</div>
);
}
}
ReactDOM.render(
<HelloMessage name="Taylor" />,
document.getElementById('root')
);
Here my .babelrc file
{
"presets":[
"react",
"es2015"
]
}
I have already install latest version of node.js
Thanks in Advance
Nilesh Kulkarni
Share Improve this question edited Oct 30, 2020 at 12:22 Nilesh Kulkarni asked Oct 30, 2020 at 10:28 Nilesh KulkarniNilesh Kulkarni 251 silver badge8 bronze badges 2-
1
Error message is telling you that you're using
webpack -d
without specifying an argument after-d
. You can find a list of valid argument value here – JulianCDC Commented Oct 30, 2020 at 10:33 - Thank you very much i have added the value for devtool in webpack.config.js file but no luck....still facing the error – Nilesh Kulkarni Commented Oct 30, 2020 at 10:58
2 Answers
Reset to default 4You have to specify devtool, either by using -d devtools
or by putting
module.exports = {
...
devtool: 'source-map'
...
};
in your webpack.config.js
.
If you chose to change the webpack.config.js
file you don't need the -d
option, if you use -d
you must specify an argument after or it will throw an error.
As the error message says, you're missing a value for the -d (--devtool) argument. You can find a list of valid values on this list. You can add this directly to your webpack config as follows:
module.exports = {
...
devtool: 'source-map' // or any other valid value here
...
};
You only need to have a value for devtool in the config if you want to use a value, similarly you only need to use the -d
argument in the CLI if you are going to pass a value through the CLI. If you don't want to use a devtool, remove it from your webpack config and change your dev script to webpack -w
. However, for development, you'll likely want sourcemaps, so I'd remend using devtool: 'source-map'
(you'll still want to change your dev script to webpack -w
).
本文标签: javascriptError while running npm run dev command in react applicationStack Overflow
版权声明:本文标题:javascript - Error while running npm run dev command in react application - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744696542a2620312.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论