I have just started with ReactJS. I cannot start the server using npm start
since start script is not in package.json
, when I include start in scripts, and then try npm start
, this shows up
20 error code ELIFECYCLE
21 error errno 1
22 error menaluxe@1.0.0 start: `search.min.js start`
22 error Exit status 1
23 error Failed at the menaluxe@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
I would be really, really thankful if someone can help me with this.
Here is my package.json
:
{
"name": "menaluxe",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "search.min.js start",
"build": "webpack && uglifyjs ./assets/build/postadd.js -c -m -o ./assets/build/postadd.min.js && uglifyjs ./assets/build/search.js -c -m -o ./assets/build/search.min.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.15.3",
"babel": "^6.5.2",
"babel-core": "^6.18.2",
"babel-loader": "^6.2.5",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.3.13",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"bootstrap-without-jquery": "^1.0.4",
"css-loader": "^0.26.1",
"file-loader": "^0.9.0",
"flux": "^3.1.0",
"history": "^1.17.0",
"images-require-hook": "^1.0.3",
"jquery": "^3.2.1",
"react": "^15.0.1",
"react-addons-test-utils": "^15.4.1",
"react-dom": "^15.0.1",
"react-ga": "^2.1.2",
"react-prop-types": "^0.4.0",
"react-pure-render": "^1.0.2",
"react-router": "^3.0.0",
"style-loader": "^0.13.1",
"superagent": "^3.2.1",
"uglify-js": "^2.7.4",
"unminified-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.7",
"webpack": "^1.13.3"
}
}
I am sure you have already run npm install
.
Depends on how your project is set up, you may not need a start
.
If your webpack is doing the start local server for you, you can just do npm build
, and see what happens.
If that does not start a local server, you can always build the project using npm build
and then start the local server yourself by using http-server
package inside the build folder. When you run build
, it should generate a new folder called build
or dist
or something like that.
https://www.npmjs.com/package/http-server
Install this package globally, then in the terminal type http-server ./build
or dist or wherever your project builds to.
For development use Use Webpack dev server
npm install webpack-dev-server@latest webpack-cli@latest
Add to package.json
"scripts": {
"build-dev": "webpack",
"dev-server": "webpack-dev-server"
}
Add webpack.config.js if you dont have
const path = require('path');
module.exports ={
return {
entry: './src/app.js',
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
rules: [{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
}]
},
devtool: 'cheap-module-eval-source-map',
devServer: {
contentBase: path.join(__dirname, 'public'),
historyApiFallback: true,
publicPath: '/'
}
};
}
From terminal
npm run build-dev
Please change script block in package.json like below :
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject" }
then run "npm run start " in your terminal
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.