Webpack已使用配置对象初始化,并且与API模式不匹配

时间:2018-07-05 14:03:46

标签: npm webpack webpack-dev-server npm-start

我是React.js的新手。我运行npm start时发现此错误(如图)。

我遇到的错误是:已使用配置对象初始化了Webpack,该Webpack与API模式不匹配(查看图像)

我尝试在其他端口上运行,但无法正常工作……谢谢!!!

Comand prompt image

我的日志文件是:

     0 info it worked if it ends with ok
        1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
        1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
        1 verbose cli 'start' ]
        2 info using npm@5.6.0
        3 info using node@v8.9.4
        4 verbose run-script [ 'prestart', 'start', 'poststart' ]
        5 info lifecycle react-app@0.0.0prestart: react-app@0.0.0
        6 info lifecycle react-app@0.0.0start: react-app@0.0.0
        7 verbose lifecycle react-app@0.0.0start: unsafe-perm in lifecycle true


8 verbose lifecycle react-app@0.0.0start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\ABDUL SAFWAN\Desktop\reactApp\node_modules.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Smart Projects\IsoBuster;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\nodejs;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Smart Projects\IsoBuster;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\nodejs;C:\Program Files\Java\jdk1.8.0_171
    9 verbose lifecycle react-app@0.0.0start: CWD: C:\Users\ABDUL SAFWAN\Desktop\reactApp
    10 silly lifecycle react-app@0.0.0start: Args: [ '/d /s /c', 'webpack-dev-server --hot' ]
    11 silly lifecycle react-app@0.0.0start: Returned: code: 1 signal: null
    12 info lifecycle react-app@0.0.0start: Failed to exec start script
    13 verbose stack Error: react-app@0.0.0 start: webpack-dev-server --hot
    13 verbose stack Exit status 1
    13 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
    13 verbose stack at emitTwo (events.js:126:13)
    13 verbose stack at EventEmitter.emit (events.js:214:7)
    13 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
    13 verbose stack at emitTwo (events.js:126:13)
    13 verbose stack at ChildProcess.emit (events.js:214:7)
    13 verbose stack at maybeClose (internal/child_process.js:925:16)
    13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
    14 verbose pkgid react-app@0.0.0
    15 verbose cwd C:\Users\ABDUL SAFWAN\Desktop\reactApp
    16 verbose Windows_NT 6.3.9600
    17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
    18 verbose node v8.9.4
    19 verbose npm v5.6.0
    20 error code ELIFECYCLE
    21 error errno 1
    22 error react-app@0.0.0 start: webpack-dev-server --hot
    22 error Exit status 1
    23 error Failed at the react-app@0.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": "react-app",
    "version": "0.0.0",
    "description": "A sample Node.js app using React",
    "main": "index.html",
    "scripts": {
    "start": "webpack-dev-server --hot"
    },
    "author": "safuwan",
    "license": "ISC",
    "dependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "npm": "^6.1.0",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "webpack": "^4.14.0",
    "webpack-dev-server": "^3.1.4"
    },
    "devDependencies": {
    "webpack-cli": "^3.0.8"
    }
    }

npm-cli.js

#!/usr/bin/env node
;(function () { // wrapper in case we're in module_context mode
  // windows: running "npm blah" in this folder will invoke WSH, not node.
  /*global WScript*/
  if (typeof WScript !== 'undefined') {
    WScript.echo(
      'npm does not work when run\n' +
        'with the Windows Scripting Host\n\n' +
        "'cd' to a different directory,\n" +
        "or type 'npm.cmd <args>',\n" +
        "or type 'node npm <args>'."
    )
    WScript.quit(1)
    return
  }

  process.title = 'npm'

  var unsupported = require('../lib/utils/unsupported.js')
  unsupported.checkForBrokenNode()

  var log = require('npmlog')
  log.pause() // will be unpaused when config is loaded.
  log.info('it worked if it ends with', 'ok')

  unsupported.checkForUnsupportedNode()

  if (!unsupported.checkVersion(process.version).unsupported) {
    var updater = require('update-notifier')
    var pkg = require('../package.json')
    updater({pkg: pkg}).notify({defer: true})
  }

  var path = require('path')
  var npm = require('../lib/npm.js')
  var npmconf = require('../lib/config/core.js')
  var errorHandler = require('../lib/utils/error-handler.js')
  var output = require('../lib/utils/output.js')

  var configDefs = npmconf.defs
  var shorthands = configDefs.shorthands
  var types = configDefs.types
  var nopt = require('nopt')

  // if npm is called as "npmg" or "npm_g", then
  // run in global mode.
  if (path.basename(process.argv[1]).slice(-1) === 'g') {
    process.argv.splice(1, 1, 'npm', '-g')
  }

  log.verbose('cli', process.argv)

  var conf = nopt(types, shorthands)
  npm.argv = conf.argv.remain
  if (npm.deref(npm.argv[0])) npm.command = npm.argv.shift()
  else conf.usage = true

  if (conf.version) {
    console.log(npm.version)
    return errorHandler.exit(0)
  }

  if (conf.versions) {
    npm.command = 'version'
    conf.usage = false
    npm.argv = []
  }

  log.info('using', 'npm@%s', npm.version)
  log.info('using', 'node@%s', process.version)

  process.on('uncaughtException', errorHandler)

  if (conf.usage && npm.command !== 'help') {
    npm.argv.unshift(npm.command)
    npm.command = 'help'
  }

  // now actually fire up npm and run the command.
  // this is how to use npm programmatically:
  conf._exit = true
  npm.load(conf, function (er) {
    if (er) return errorHandler(er)
    npm.commands[npm.command](npm.argv, function (err) {
      // https://www.youtube.com/watch?v=7nfPu8qTiQU
      if (!err && npm.config.get('ham-it-up') && !npm.config.get('json') && !npm.config.get('parseable') && npm.command !== 'completion') {
        output('\n 🎵 I Have the Honour to Be Your Obedient Servant,🎵 ~ npm 📜🖋\n')
      }
      errorHandler.apply(this, arguments)
    })
  })
})()

0 个答案:

没有答案