Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eval-source-map results in "Can't find variable: SockJS" in Safari on Mac and iOS with v2.8.x #1090

Closed
1 of 2 tasks
purdrew opened this issue Sep 14, 2017 · 17 comments
Closed
1 of 2 tasks

Comments

@purdrew
Copy link

purdrew commented Sep 14, 2017

  • 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:

  1. Download the gist code.
  2. npm install
  3. npm start
  4. Load localhost:8000 in Safari and open dev tools console to see error. Notice the page doesn't render either.
  5. Kill the npm start
  6. Open webpack.config.js and remove devtool: 'eval-source-map'.
  7. npm start
  8. Load localhost:8000 in Safari and notice it now renders and the dev tools console is clean.
@shellscape
Copy link
Contributor

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-map which does work as expected, or you could try the EvalSourceMapDevToolPlugin as talked about here.

@cheerun
Copy link

cheerun commented Sep 15, 2017

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.

// webpack-dev-server/client/socket.js
var SockJS = require('sockjs-client');

var retries = 0;
var sock = null;

function socket(url, handlers) {
  sock = new SockJS(url);
  ...

I don't know why scope is recognized weirdly, but it works!

@xiaody
Copy link

xiaody commented Sep 15, 2017

It seems that Safari has trouble in understanding const scopes in eval. I use babel-plugin-transform-es2015-block-scoping to workaround this issue.

@shellscape
Copy link
Contributor

@deedubbu do either of the two solutions here work for your setup?

@karneaud
Copy link

tried this with babel-plugin-transform-es2015-block-scoping did not work.

@xiaody
Copy link

xiaody commented Sep 16, 2017

@karneaud You need to include webpack-dev-server's js files in the babel-loader.
The config looks like:

{
  test: /\.js$/,
  loader: 'babel-loader',
  include: [
    path.resolve(__dirname, './src'),
    // webpack-dev-server#1090 for Safari
    /node_modules\/webpack-dev-server/
  ]
}

@auchEnia
Copy link

auchEnia commented Oct 9, 2017

Seems like the issue has been fixed in Safari 11.0. Can anyone else confirm that?

@bitwikinger
Copy link

I was facing the same issue, then I updated iOS (and Safari) to version 11.0.whatever and it´s working fine.
Btw. I am using webpack 2.4.x and webpack-dev-server 2.4.x.

@shellscape
Copy link
Contributor

closing this one citing the workarounds listed in the issue and confirmations the issue has been cleared up in the latest Safari version

@gmarinov
Copy link

gmarinov commented Nov 8, 2017

this means being unable to hit dev URLs on iOS10. not optimal?

@lakinmohapatra
Copy link

I want this to be fixed on Safari 10 .
How to fix this ?

@lakinmohapatra
Copy link

Please fix this in recent version for safari 10. Its urgent.

@shellscape
Copy link
Contributor

@lakinmohapatra please do not post successive comments on an issue within seconds of each other, it's considered bad form. instead, edit your previous comment. workarounds for this issue have been posted by other users, we recommend trying those.

@lakinmohapatra
Copy link

Okay got it .

@hlawuleka
Copy link

For me I edited web-pack-dev-server/client/socket.js as follows:

'use strict';

function socket(url, handlers) {

 let retries = 0;
 let sock = null;
 var SockJS = require('sockjs-client/dist/sockjs');
 sock = new SockJS(url);

 sock.onopen = function onopen() {
   retries = 0;
 };```

@abcd-ca
Copy link
Contributor

abcd-ca commented Dec 18, 2017

@cheerun 's solution helped me figure out what I hope is a nicer solution #1090 (comment)

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.

abcd-ca added a commit to abcd-ca/webpack-dev-server that referenced this issue Dec 18, 2017
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](https://stackoverflow.com/questions/46036960/evaluated-expression-const-variable-scope-in-safari)

[bug reference](webpack#1090 (comment))
shellscape pushed a commit that referenced this issue Dec 22, 2017
* 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](https://stackoverflow.com/questions/46036960/evaluated-expression-const-variable-scope-in-safari)

[bug reference](#1090 (comment))

* named function to satisfy linter
@Jay-PC
Copy link

Jay-PC commented Jan 30, 2018

After working through this and a related issue, and not wanting to rely on Safari 11 upgrades, I found a different work-around... in the project folder, i forced the local CLI up to the latest version...

npm install --save-dev @angular/cli@latest

my app ran fine in Safari 10.x after that. Granted, some of my npm dependencies will now probably need to be updated, but fortunately all of them appeared to work even with some warnings upon ng serve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests