簡體   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