我有一个使用webpack的反应应用程序在更新的Chrome浏览器中工作正常但在Chrome 34中引发错误。我们有一个客户端需要使用Chrome 34,所以我们必须支持它。
Uncaught SyntaxError: Use of const in strict mode.
错误发生在项目的webpack包文件中。这是bundle.js文件中抛出错误的行。
"use strict";
eval("/* WEBPACK VAR INJECTION */(function(__resourceQuery) {\n\n/* global __resourceQuery WorkerGlobalScope self */\n/* eslint prefer-destructuring: off */\n\nconst url = __webpack_require__(\"./node_modules/url/url.js\");\nconst stripAnsi = __webpack_require__(\"./node_modules/strip-ansi/index.js\");\nconst log = __webpack_require__(\"./node_modules/loglevel/lib/loglevel.js\").getLogger('webpack-dev-server');\nconst socket = __webpack_require__(\"./node_modules/webpack-dev-server/client/socket.js\");\nconst overlay = __webpack_require__(\"./node_modules/webpack-dev-server/client/overlay.js\");\n\nfunction getCurrentScriptSource() {\n // `document.currentScript` is the most accurate way to find the current script,\n // but is not supported in all browsers.\n if (document.currentScript) { return document.currentScript.getAttribute('src'); }\n // Fall back to getting all scripts in the document.\n const scriptElements = document.scripts || [];\n const currentScript = scriptElements[scriptElements.length - 1];\n if (currentScript) { return currentScript.getAttribute('src'); }\n // Fail as there was no script to use.\n throw new Error('[WDS] Failed to get current script source.');\n}\n\nlet urlParts;\nlet hotReload = true;\nif (typeof window !== 'undefined') {\n const qs = window.location.search.toLowerCase();\n hotReload = qs.indexOf('hotreload=false') === -1;\n}\nif (true) {\n // If this bundle is inlined, use the resource query to get the correct url.\n urlParts = url.parse(__resourceQuery.substr(1));\n} else {\n // Else, get the url from the <script> this file was called with.\n let scriptHost = getCurrentScriptSource();\n // eslint-disable-next-line no-useless-escape\n scriptHost = scriptHost.replace(/\\/[^\\/]+$/, '');\n urlParts = url.parse((scriptHost || '/'), false, true);\n}\n\nif (!urlParts.port || urlParts.port === '0') {\n urlParts.port = self.location.port;\n}\n\nlet hot = false;\nlet initial = true;\nlet currentHash = '';\nlet useWarningOverlay = false;\nlet useErrorOverlay = false;\nlet useProgress = false;\n\nconst INFO = 'info';\nconst WARNING = 'warning';\nconst ERROR = 'error';\nconst NONE = 'none';\n\n// Set the default log level\nlog.setDefaultLevel(INFO);\n\n// Send messages to the outside, so plugins can consume it.\nfunction sendMsg(type, data) {\n if (\n typeof self !== 'undefined' &&\n (typeof WorkerGlobalScope === 'undefined' ||\n !(self instanceof WorkerGlobalScope))\n ) {\n self.postMessage({\n type: 'webpack' + type,\n data: data\n }, '*');\n }\n}\n\nconst onSocketMsg = {\n hot: function msgHot() {\n hot = true;\n log.info('[WDS] Hot Module Replacement enabled.');\n },\n invalid: function msgInvalid() {\n log.info('[WDS] App updated. Recompiling...');\n // fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.\n if (useWarningOverlay || useErrorOverlay) overlay.clear();\n sendMsg('Invalid');\n },\n hash: function msgHash(hash) {\n currentHash = hash;\n },\n 'still-ok': function stillOk() {\n log.info('[WDS] Nothing changed.');\n if (useWarningOverlay || useErrorOverlay) overlay.clear();\n sendMsg('StillOk');\n },\n 'log-level': function logLevel(level) {\n const hotCtx = __webpack_require__(\"./node_modules/webpack/hot ^\\\\.\\\\/log$\");\n const contextKeys = hotCtx.keys();\n if (contextKeys.length && contextKeys['./log']) {\n hotCtx('./log').setLogLevel(level);\n }\n switch (level) {\n case INFO:\n case ERROR:\n log.setLevel(level);\n break;\n case WARNING:\n // loglevel's warning name is different from webpack's\n log.setLevel('warn');\n break;\n case NONE:\n log.disableAll();\n break;\n default:\n log.error('[WDS] Unknown clientLogLevel \\'' + level + '\\'');\n }\n },\n overlay: function msgOverlay(value) {\n if (typeof document !== 'undefined') {\n if (typeof (value) === 'boolean') {\n useWarningOverlay = false;\n useErrorOverlay = value;\n } else if (value) {\n useWarningOverlay = value.warnings;\n useErrorOverlay = value.errors;\n }\n }\n },\n progress: function msgProgress(progress) {\n if (typeof document !== 'undefined') {\n useProgress = progress;\n }\n },\n 'progress-update': function progressUpdate(data) {\n if (useProgress) log.info('[WDS] ' + data.percent + '% - ' + data.msg + '.');\n },\n ok: function msgOk() {\n sendMsg('Ok');\n if (useWarningOverlay || useErrorOverlay) overlay.clear();\n if (initial) return initial = false; // eslint-disable-line no-return-assign\n reloadApp();\n },\n 'content-changed': function contentChanged() {\n log.info('[WDS] Content base changed. Reloading...');\n self.location.reload();\n },\n warnings: function msgWarnings(warnings) {\n log.warn('[WDS] Warnings while compiling.');\n const strippedWarnings = warnings.map(function map(warning) { return stripAnsi(warning); });\n sendMsg('Warnings', strippedWarnings);\n for (let i = 0; i < strippedWarnings.length; i++) { log.warn(strippedWarnings[i]); }\n if (useWarningOverlay) overlay.showMessage(warnings);\n\n if (initial) return initial = false; // eslint-disable-line no-return-assign\n reloadApp();\n },\n errors: function msgErrors(errors) {\n log.error('[WDS] Errors while compiling. Reload prevented.');\n const strippedErrors = errors.map(function map(error) { return stripAnsi(error); });\n sendMsg('Errors', strippedErrors);\n for (let i = 0; i < strippedErrors.length; i++) { log.error(strippedErrors[i]); }\n if (useErrorOverlay) overlay.showMessage(errors);\n },\n error: function msgError(error) {\n log.error(error);\n },\n close: function msgClose() {\n log.error('[WDS] Disconnected!');\n sendMsg('Close');\n }\n};\n\nlet hostname = urlParts.hostname;\nlet protocol = urlParts.protocol;\n\n\n// check ipv4 and ipv6 `all hostname`\nif (hostname === '0.0.0.0' || hostname === '::') {\n // why do we need this check?\n // hostname n/a for file protocol (example, when using electron, ionic)\n // see: https://github.com/webpack/webpack-dev-server/pull/384\n // eslint-disable-next-line no-bitwise\n if (self.location.hostname && !!~self.location.protocol.indexOf('http')) {\n hostname = self.location.hostname;\n }\n}\n\n// `hostname` can be empty when the script path is relative. In that case, specifying\n// a protocol would result in an invalid URL.\n// When https is used in the app, secure websockets are always necessary\n// because the browser doesn't accept non-secure websockets.\nif (hostname && (self.location.protocol === 'https:' || urlParts.hostname === '0.0.0.0')) {\n protocol = self.location.protocol;\n}\n\nconst socketUrl = url.format({\n protocol: protocol,\n auth: urlParts.auth,\n hostname: hostname,\n port: urlParts.port,\n pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : urlParts.path\n});\n\nsocket(socketUrl, onSocketMsg);\n\nlet isUnloading = false;\nself.addEventListener('beforeunload', function beforeUnload() {\n isUnloading = true;\n});\n\nfunction reloadApp() {\n if (isUnloading || !hotReload) {\n return;\n }\n if (hot) {\n log.info('[WDS] App hot update...');\n // eslint-disable-next-line global-require\n const hotEmitter = __webpack_require__(\"./node_modules/webpack/hot/emitter.js\");\n hotEmitter.emit('webpackHotUpdate', currentHash);\n if (typeof self !== 'undefined' && self.window) {\n // broadcast update to window\n self.postMessage('webpackHotUpdate' + currentHash, '*');\n }\n } else {\n log.info('[WDS] App updated. Reloading...');\n self.location.reload();\n }\n}\n\n/* WEBPACK VAR INJECTION */}.call(exports, \"?http://localhost:8080\"))\n\n//////////////////\n// WEBPACK FOOTER\n// (webpack)-dev-server/client?http://localhost:8080\n// module id = ./node_modules/webpack-dev-server/client/index.js?http:/localhost:8080\n// module chunks = 0 1\n\n//# sourceURL=webpack:///(webpack)-dev-server/client?");
这是我的package.json文件
{
"name": "ava",
"version": "0.1.0",
"private": true,
"main": "app.js",
"dependencies": {
"autoprefixer": "7.1.2",
"babel-core": "^6.26.0",
"babel-eslint": "7.2.3",
"babel-jest": "20.0.3",
"babel-loader": "^7.1.2",
"babel-preset-react-app": "^3.0.3",
"babel-runtime": "6.26.0",
"broadwayjs": "0.0.2",
"case-sensitive-paths-webpack-plugin": "2.1.1",
"chalk": "1.1.3",
"css-loader": "0.28.4",
"dotenv": "4.0.0",
"eslint": "4.4.1",
"eslint-config-react-app": "^2.0.1",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "2.35.0",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-react": "7.1.0",
"extract-text-webpack-plugin": "3.0.0",
"file-loader": "0.11.2",
"fs-extra": "3.0.1",
"html-webpack-plugin": "^2.30.1",
"jest": "20.0.4",
"object-assign": "4.1.1",
"postcss-flexbugs-fixes": "3.2.0",
"postcss-loader": "2.0.6",
"promise": "8.0.1",
"query-string": "^5.0.1",
"react": "^16.0.0",
"react-dev-utils": "^4.1.0",
"react-dom": "^16.0.0",
"react-google-maps": "^9.2.2",
"react-polyfill": "0.0.2",
"react16-spinjs": "^3.0.1",
"style-loader": "^0.19.0",
"sw-precache-webpack-plugin": "0.11.4",
"underscore": "^1.8.3",
"url-loader": "0.5.9",
"webpack": "3.5.1",
"webpack-dev-server": "2.8.2",
"webpack-manifest-plugin": "1.2.1",
"whatwg-fetch": "2.0.3"
},
"scripts": {
"start": "webpack-dev-server --open",
"dev": "webpack -d --watch --hot",
"build": "webpack -d --watch --hot",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.11.0"
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.js?(x)",
"<rootDir>/src/**/?(*.)(spec|test).js?(x)"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node"
]
},
"babel": {
"presets": [
"react-app"
]
},
"eslintConfig": {
"extends": "react-app"
}
}
有关可能导致此问题的任何想法仅限于Chrome 34?
答案 0 :(得分:0)
您应该使用Babel env preset定位您要查找的浏览器。
将您的babel配置更改为此类(未经测试):
interaction <- lm(Y ~ X1 * X2, data=df)
visreg(interaction,"X1", by="X2",
overlay = TRUE, partial = FALSE, rug = FALSE)