我刚开始使用ReactJS。我无法使用npm start
启动服务器,因为启动脚本不在package.json
中,当我在脚本中包含启动,然后尝试npm start
时,会显示
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 ]
如果有人可以帮助我,我将非常感激。
这是我的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"
}
}
答案 0 :(得分:0)
我确定您已经运行了npm install
。
取决于项目的设置方式,您可能不需要start
。
如果您的webpack正在为您启动本地服务器,则只需执行npm build
,然后看看会发生什么。
如果这样不能启动本地服务器,则始终可以使用npm build
来构建项目,然后使用build文件夹中的http-server
包来自己启动本地服务器。运行build
时,它将生成一个名为build
或dist
或类似名称的新文件夹。
https://www.npmjs.com/package/http-server
全局安装此软件包,然后在终端中键入http-server ./build
或dist或将项目创建到的任何位置。
答案 1 :(得分:0)
用于开发 使用Webpack开发服务器
npm install webpack-dev-server@latest webpack-cli@latest
添加到package.json
"scripts": {
"build-dev": "webpack",
"dev-server": "webpack-dev-server"
}
如果没有,请添加webpack.config.js
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: '/'
}
};
}
从终端
npm run build-dev
答案 2 :(得分:0)
请按如下所示更改package.json中的脚本块:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject" }
然后在您的终端中运行“ npm run start”