我在另一台计算机上安装了React项目,突然在浏览器中的控制台充满了这些:
sockjs-client:websocket unload +96ms
browser.js:123 sockjs-client:main using url +0ms http://localhost:8080/sockjs-node
browser.js:123 sockjs-client:utils:url same +3ms http://localhost:8080/sockjs-node http://localhost:8080/category/PLvbS24bigqq80_SfZtLIF_1MUhSuVCOGY true
browser.js:123 sockjs-client:info-receiver http://localhost:8080/sockjs-node +1ms
log.js:5 [HMR] Waiting for update signal from WDS...
browser.js:123 sockjs-client:info-receiver doXhr +325ms http://localhost:8080/sockjs-node/info
browser.js:123 sockjs-client:browser:xhr GET +2ms http://localhost:8080/sockjs-node/info
browser.js:123 sockjs-client:browser:xhr readyState +157ms 2
browser.js:123 sockjs-client:browser:xhr readyState +1ms 3
browser.js:123 sockjs-client:browser:xhr status +1ms 200
browser.js:123 sockjs-client:browser:xhr chunk +0ms
browser.js:123 sockjs-client:browser:xhr readyState +3ms 4
browser.js:123 sockjs-client:browser:xhr status +1ms 200
browser.js:123 sockjs-client:browser:xhr finish +1ms 200 {"websocket":true,"origins":["*:*"],"cookie_needed":false,"entropy":3957747340}
browser.js:123 sockjs-client:info-receiver finish +2ms Object {websocket: true, origins: Array(1), cookie_needed: false, entropy: 3957747340} 166
browser.js:123 sockjs-client:info-receiver _cleanup +4ms
browser.js:123 sockjs-client:main _receiveInfo +1ms 166
browser.js:123 sockjs-client:main info +2ms Object {websocket: true, origins: Array(1), cookie_needed: false, entropy: 3957747340, nullOrigin: false…}
browser.js:123 sockjs-client:websocket enabled +2ms
browser.js:123 sockjs-client:utils:transport enabled +0ms websocket
browser.js:123 sockjs-client:utils:transport enabled +1ms xhr-streaming
browser.js:123 sockjs-client:utils:transport disabled +1ms xdr-streaming
browser.js:123 sockjs-client:utils:transport enabled +1ms eventsource
browser.js:123 sockjs-client:utils:transport enabled +1ms iframe-eventsource
browser.js:123 sockjs-client:utils:transport enabled +0ms htmlfile
browser.js:123 sockjs-client:utils:transport enabled +1ms iframe-htmlfile
browser.js:123 sockjs-client:utils:transport enabled +1ms xhr-polling
browser.js:123 sockjs-client:utils:transport disabled +1ms xdr-polling
browser.js:123 sockjs-client:utils:transport enabled +1ms iframe-xhr-polling
browser.js:123 sockjs-client:utils:transport enabled +1ms jsonp-polling
...
sockjs-client通过热重写和我自己的控制台日志混合了日志。我没有在网上找到任何帮助。
我的package.json
{
"name": "template-react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot",
"build": "webpack --config ./webpack.config.production.js --progress --profile --colors"
},
"repository": {
"type": "git"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"isomorphic-fetch": "^2.2.1",
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2017": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"file-loader": "^0.11.1",
"react-hot-loader": "^3.0.0-beta.6",
"webpack": "^3.2.0",
"webpack-dev-server": "^2.4.5"
},
"babel": {
"presets": [
"es2017",
"stage-2",
"react"
],
"plugins": [
"react-hot-loader/babel"
]
}
}
和webpack.config.js
const webpack = require('webpack')
const path = require('path')
module.exports = {
devtool: 'source-map',
entry: {
'app': [
'babel-polyfill',
'react-hot-loader/patch',
'./src/index'
]
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js'
},
resolve : {
extensions: ['.js', '.jsx'],
modules: [
path.resolve('src'),
path.resolve('static'),
path.resolve('node_modules')
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV : JSON.stringify('development'),
BROWSER : JSON.stringify(true)
}
}),
],
module: {
rules: [
{
test: /\.jsx|js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
}
}
答案 0 :(得分:1)
Sockjs
模块正在使用debug
节点模块登录到控制台。环境变量DEBUG(用于设置debug
模块)设置为*
,并保存在localStorage中。因此,我在localhost:8080
上运行的新项目与同一台计算机上的某个先前项目一样使用了DEBUG='*'
,因此记录了日志。
我尝试将process.env.DEBUG
中的webpack.config.js
设置为其他值,但它没有在localStorage中更改值,因此它会保留日志记录。所以我只是从localStorage手动删除了值。