Skip to content

ReferenceError: Can't find variable: SockJS #1094

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

Closed
1 of 2 tasks
karneaud opened this issue Sep 15, 2017 · 1 comment
Closed
1 of 2 tasks

ReferenceError: Can't find variable: SockJS #1094

karneaud opened this issue Sep 15, 2017 · 1 comment

Comments

@karneaud
Copy link

karneaud commented Sep 15, 2017

  • Operating System: Latest Docker for Node
  • Node Version: 8.5
  • NPM Version: 5.3
  • webpack Version: 2.7.0
  • webpack-dev-server Version: 2.8.2
  • This is a feature request
  • This is a bug

Code

  // webpack.config.js
  context: resolve(__dirname, 'src'),
  devtool: ifProduction(!!process.env.SOURCE_MAP && 'source-map', 'eval'),
  stats: {
    colors: true,
    children: false,
    chunks: false,
    chunkModules: false,
    modules: false
  },
  devServer: {
    port: process.env.WEBPACK_SERVER_PORT,
    disableHostCheck: true,
    host: CURRENT_IP,
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
....
  entry: {
    app: removeEmpty([
      // fix HMR in IE
      ifDevelopment('eventsource-polyfill'),

      // bundle the client for webpack-dev-server
      // and connect to the provided endpoint
      // it enable HMR from external devices
      ifDevelopment(`webpack-dev-server/client?${externalPath}`),

      './app/main.js'
    ])
  },
  resolve: {
    alias: {
      'src': resolve(__dirname, 'src'),
      'app': resolve(__dirname, 'src/app'),
      'styles': resolve(__dirname, 'src/styles'),
      'lib': resolve(__dirname, 'lib'),
      'jquery': join(__dirname, 'node_modules/jquery/dist/jquery')
    },
    modules: ['node_modules', 'shared']
  },
  output: {
    publicPath: ifDevelopment(externalPath, '/'),
    filename: ifProduction('static/js/bundle.[name].[chunkhash:8].js', 'bundle.[name].js'),
    chunkFilename: ifProduction('static/js/chunk.[name].[chunkhash:8].js', 'chunk.[name].js'),
    path: resolve(__dirname, 'dist'),
    pathinfo: ifNotProduction()
  },

....

ifProduction(
      new InlineManifestWebpackPlugin({
        name: 'webpackManifest'
      })
    ),

    // ensures npm install <library> forces a project rebuild
    ifDevelopment(new WatchMissingNodeModulesPlugin(rootNodeModulesPath)),

    // enable HMR globally
    ifDevelopment(new webpack.HotModuleReplacementPlugin()),
    // don't compile if error
    ifDevelopment(new webpack.NoEmitOnErrorsPlugin()),

    // prints more readable module names in the browser console on HMR updates
    ifNotProduction(new webpack.NamedModulesPlugin()),

    ifProduction(
      // minify and optimize the javaScript
      new webpack.optimize.UglifyJsPlugin({
        sourceMap: !!process.env.SOURCE_MAP,
        compress: {
          screw_ie8: true,
          warnings: false
        },
        mangle: {
          screw_ie8: true
        },
        output: {
          comments: false,
          screw_ie8: true
        }
      })
    ),

    process.env.BUNDLE_ANALYZER_REPORT && ifProduction(new BundleAnalyzerPlugin()),

    ifProduction(new ExtractTextPlugin('static/css/[name].[contenthash:8].css')),

    new HtmlWebpackPlugin({
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      chunksSortMode: 'dependency',
      template: join(resolve(__dirname, 'src'), 'index.pug'),
      inject: true,
      minify: ifProduction({
        removeComments: true,
        collapseWhitespace: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true
      })
    }),

    process.env.BROWSER_SYNC && ifNotProduction(
      new BrowserSyncPlugin({
        open: false,
        port: process.env.BROWSER_SYNC_PORT,
        proxy: externalPath
      }, {
        // prevent BrowserSync from reloading the page
        // and let Webpack Dev Server take care of this
        reload: true
      })
    ),
  // additional code, remove if not needed.
const SockJS = __webpack_require__(/*! sockjs-client */ "../node_modules/sockjs-client/lib/entry.js");

let retries = 0;
let sock = null;

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

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

  sock.onclose = function onclose() {
    if (retries === 0) { handlers.close(); }

    // Try to reconnect.
    sock = null;

Expected Behaviour

Should load website in Safari 10.1.2. Works as expected in other browsers

Actual Behaviour

Errors with the following in Safari 10.1.2

ReferenceError: Can't find variable: SockJS

For Bugs; How can we reproduce the behavior?

install
webpack Version: 2.7.0
webpack-dev-server Version: 2.8.2 with Browsersync

For Features; What is the motivation and/or use-case for the feature?

@shellscape
Copy link
Contributor

This issue is already being tracked in #1090. Please see the comments in that issue add your comments for your unique configuration there.

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

No branches or pull requests

2 participants