繁体   English   中英

npm start不会在本地运行我的项目

[英]npm start won't run my project locally

我刚刚开始使用ReactJS。 我无法使用npm start启动服务器,因为启动脚本不在package.json ,当我在脚本中包含start,然后尝试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"
  }
}

我确定您已经运行了npm install

根据项目的设置方式,您可能不需要start

如果您的webpack正在为您启动本地服务器,则只需执行npm build ,然后看看会发生什么。

如果那不能启动本地服务器,则始终可以使用npm build来构建项目,然后使用build文件夹中的http-server包来自己启动本地服务器。 运行build ,它将生成一个名为builddist或类似名称的新文件夹。

https://www.npmjs.com/package/http-server

全局安装此软件包,然后在终端中键入http-server ./build或dist或项目生成到的任何位置。

供开发使用使用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

请按如下所示更改package.json中的脚本块:

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject" }

然后在终端中运行“ npm run start”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM