参数数量不足或找不到条目

时间:2018-09-28 08:48:02

标签: javascript reactjs webpack

我正在构建一个通过使用socket.io使用客户端-服务器通信和服务器-谷歌云平台通信的应用程序。对于前端部分,我使用React,其中有两个组件App和Touch。将来我将更改项目结构,但是现在看起来像这样

我的项目结构如下:

nodemodulesFolder
publicFolder
  jsFolder
     client.js
     socket.io.js
     socket.io.js
     socket.io.js.map
     touch.js
  viewFolder
     App.js
     index.css
     Touch.js
  index.js
  routes.js
.dockerignore
.env
.gitignore
deployment.yaml
Dockerfile
index.js
ingress.yaml
Jenkinsfike
package.json
package-lock.json
server.js
webpack.config.js

这是我的webpack.config.js

'use strict'

module.exports = {
  entry: __dirname + '/cp-test-app/public/index.js',
  output: {
    path: __dirname + '/cp-test-app/public/',
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015']
        }
      },
      { test: /\.css$/,
        use: [
          { loader: "style-loader" },
          { loader: "css-loader" }
        ]
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.jsx']
  }
};

这些是我用来运行应用程序的脚本:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack --mode development",
    "build": "webpack --mode production"
}

但是以某种方式我得到了以下错误:

  

@开始/用户/ raulvilloravalencia / OneDrive-马德里理工大学/ Documents / cp-test-app-2 / cp-test-app   webpack-模式开发

Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.

Hash: 14907618cdf8c7e77e94
Version: webpack 4.20.2
Time: 66ms
Built at: 2018-09-28 10:41:38

ERROR in Entry module not found: Error: Can't resolve '/Users/raulvilloravalencia/OneDrive - Universidad Politécnica de Madrid/Documents/cp-test-app-2/cp-test-app/cp-test-app/public/index.js' in '/Users/raulvilloravalencia/OneDrive - Universidad Politécnica de Madrid/Documents/cp-test-app-2/cp-test-app'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ start: `webpack --mode development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/raulvilloravalencia/.npm/_logs/2018-09-28T08_41_39_055Z-debug.log

我的package.json看起来像这样:

{
  "description": "Google Cloud Speech Playground with node.js and socket.io.",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack --mode development",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "babel": {
    "presets": [
      "env",
      "react"
    ],
    "plugins": [
      "transform-object-rest-spread"
    ]
  },
  "dependencies": {
    "@google-cloud/speech": "1.5.0",
    "@grpc/proto-loader": "^0.3.0",
    "@webpack-cli/init": "^0.1.1",
    "ajv": "^6.5.4",
    "ajv-keywords": "^3.2.0",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-register": "^6.3.13",
    "cors": "^2.8.4",
    "dotenv": "^4.0.0",
    "ejs": "^2.5.7",
    "express": "^4.16.3",
    "isomorphic-fetch": "^2.2.1",
    "json-loader": "^0.5.4",
    "nodemon": "^1.18.4",
    "path": "^0.12.7",
    "react": "^16.5.2",
    "react-dom": "^16.5.2",
    "react-engine": "^4.5.1",
    "react-router": "^3.2.1",
    "react-router-dom": "^4.2.2",
    "serialize-javascript": "^1.4.0",
    "serve-favicon": "^2.3.0",
    "socket.io": "^2.0.4"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "css-loader": "^1.0.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "nodemon": "^1.9.2",
    "webpack": "^4.20.2",
    "webpack-cli": "^3.1.1",
    "webpack-node-externals": "^1.6.0"
  }
}

1 个答案:

答案 0 :(得分:1)

Webpack正在寻找/cp-test-app-2/cp-test-app/cp-test-app/public/index.js,而它正在寻找/cp-test-app-2/cp-test-app/public/index.js

通过删除多余的webpack.config.js,在/cp-test-app中指定正确的相对路径:

'use strict'

module.exports = {
  entry: __dirname + '/public/index.js',
  output: {
    path: __dirname + '/public/',
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015']
        }
      },
      { test: /\.css$/,
        use: [
          { loader: "style-loader" },
          { loader: "css-loader" }
        ]
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.jsx']
  }
};

可能与该特定错误无关,但是您需要使用以下语法来指定模式:

webpack --mode=development
//            ^      
// Notice the equals sign.