React如何debug?
发布于 8 年前 作者 songyuwen 5605 次浏览 来自 问答

我的webpck配置文件是:

export default {
    entry: "./src/client.js",
    output: {
        filename: "./build/bundle.js"
    },
    module: {
        loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: "babel" }]
    }
}

我的package.json中的依赖和scripts

{
  "name": "test",
  "version": "1.0.0",
  "description": "test app",
  "main": "",
  "scripts": {
    "watch": "webpack --progress --colors --watch",
    "serve": "nodemon ./src/server.js --exec ./node_modules/.bin/babel-node",
    "start": "npm run watch & npm run serve"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^15.2.1",
    "react-dom": "^15.2.1",
    "react-router": "^2.6.0"
  },
  "devDependencies": {
    "babel-cli": "^6.11.4",
    "babel-core": "^6.11.4",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1",
    "webpack": "^1.13.1"
  }
}

然后我的某个react component如下:

// foo.js
import React, { Component } from "react"
//  这里忘记了 `import { Link } from 'react-router'

class Foo extends Component {
  render() {
      return (
	     <div>
		    <Link to="/bar">Bar</Link>   {/* 但在这里我使用了`<Link />` */}
		 </div>
	  )
  }
}

然后我的控制台中是这样的:

> nodemon --debug ./src/server.js --exec ./node_modules/.bin/babel-node
[nodemon] 1.10.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `./node_modules/.bin/babel-node --debug ./src/server.js`
Debugger listening on [::]:5858
 22% 12/59 build modules
Hash: 260d0d4d9073bc3eaedc  
Version: webpack 1.13.1
Time: 6143ms
      Asset     Size  Chunks             Chunk Names
./bundle.js  2.33 MB       0  [emitted]  main
    + 438 hidden modules
[nodemon] restarting due to changes...
[nodemon] starting `./node_modules/.bin/babel-node --debug ./src/server.js`
Debugger listening on [::]:5858

App now serving at http://127.0.0.1:3333

接着我使劲的刷新页面,TMD的就是页面不出来,捣鼓了好久,TMD的就是因为<Link />没有倒入,连这么个小白的模块引入问题,居然都不给我报个错,这是要逆天了的节操?

2 回复

推介使用yeoman的react-webpack脚手架 react-tuturial

@cllgeek 谢谢,不过我最不喜欢用脚手架。

回到顶部