webpack-dev-server: `eval-source-map` results in "Can't find variable: SockJS" in Safari on Mac and iOS with v2.8.x
- Operating System: macOS 10.12.6
- Node Version: v7.10.0
- NPM Version: 4.2.0
- webpack Version: 2.7.0
- webpack-dev-server Version: 2.8.2
- This is a feature request
- This is a bug
Code
Sample code here
Expected Behavior
Using the eval-source-map option for devtool should not affect the ability to render the page.
Actual Behavior
With version 2.8.x it seems like specifying eval-source-map for devtool is causing an error that is preventing rendering on Safari on Mac and iOS. Rendering seems fine on Chrome/Firefox, but when loading the page in Safari I’m getting:
ReferenceError: Can't find variable: SockJS
I suspect something in the “Cleanup Effort” commit might have broke this but haven’t identified what. Maybe something to do with uglifyJS plugin being added
How can we reproduce the behavior?
The gist has a complete code sample that exhibits the issue:
- Download the gist code.
npm installnpm start- Load
localhost:8000in Safari and open dev tools console to see error. Notice the page doesn’t render either. - Kill the
npm start - Open
webpack.config.jsand removedevtool: 'eval-source-map'. npm start- Load
localhost:8000in Safari and notice it now renders and the dev tools console is clean.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 25
- Comments: 17 (5 by maintainers)
Commits related to this issue
- iOS Safari 10 bug where SockJS couldn't be found Fixes iOS Safari 10 bug. At the root, this works around a bug where Safari's eval's scope was getting confused. Something to do with [this issue](htt... — committed to abcd-ca/webpack-dev-server by abcd-ca 7 years ago
- iOS Safari 10 bug where SockJS couldn't be found (#1238) * iOS Safari 10 bug where SockJS couldn't be found Fixes iOS Safari 10 bug. At the root, this works around a bug where Safari's eval's scop... — committed to webpack/webpack-dev-server by abcd-ca 7 years ago
@cheerun 's solution helped me figure out what I hope is a nicer solution https://github.com/webpack/webpack-dev-server/issues/1090#issuecomment-329739449
I wanted to add something that wasn’t immediately clear for others. The file to edit is located at
/node_modules/webpack-dev-server/client/socket.js
What I changed was one line, from this
function socket(url, handlers) {to this
const socket = function(url, handlers) {@shellscape I will create a PR for this.
@karneaud You need to include webpack-dev-server’s js files in the babel-loader. The config looks like:
closing this one citing the workarounds listed in the issue and confirmations the issue has been cleared up in the latest Safari version
It occurs on the not only 2.8.x, but also ~ 2.2.0. (or maybe lower version too.)
I changed code to below (with helping by @shai, my colleague at work), It works well.
I don’t know why scope is recognized weirdly, but it works!
If you haven’t already, give
devtool: 'source-map'a try. It works with the latest version as can be seen in the example here.I can certainly understand the frustration that 2.8.x introduced a regression and this has ceased to work correctly for you. There seems to be a never ending number of edge cases in the webpack world that surfaces with each release. For this particular one bugbear, we’ll happily welcome a PR from the community to resolve it. In the meantime, you might choose to use
source-mapwhich does work as expected, or you could try theEvalSourceMapDevToolPluginas talked about here.It seems that Safari has trouble in understanding
constscopes ineval. I use babel-plugin-transform-es2015-block-scoping to workaround this issue.Please fix this in recent version for safari 10. Its urgent.
I want this to be fixed on Safari 10 . How to fix this ?
this means being unable to hit dev URLs on iOS10. not optimal?