Giter VIP home page Giter VIP logo

Comments (15)

RomainLanz avatar RomainLanz commented on May 21, 2024

Hey @nicktupy! 👋

'production' or "production" are exactly the same, they are both strings.

from adonis-websocket-client.

nicktupy avatar nicktupy commented on May 21, 2024

When the Vue-CLI sets the NODE_ENV, it is set as '"production"' or '"development"' so the quotations are considered a part of the string.

if (process.env.NODE_ENV !== 'production') { //debug function }

Causes the debug to occur regardless of the NODE_ENV set by vue.

Changing if statements in src/Connection/index.js to the following solves the problem.
if (process.env.NODE_ENV !== 'production' | process.env.NODE_ENV !== "production") { //debug function }

I suspect using != vs !== would also solve the issue.

from adonis-websocket-client.

nicktupy avatar nicktupy commented on May 21, 2024

socketissue

Here is an example. The production output text you see in the log is from console.log(process.env.NODE_ENV)

Once I implemented the change I discussed in the above post, the websocket-client logs properly disappeared.

I'm not quite sure how this bug is happening, my fix shouldn't be necessary and shouldn't change anything. When logging process.env.NODE_ENV to console, I get a normal string that reads 'production' or 'development' depending on how I serve the app.

The exact same if-statement of
if (process.env.NODE_ENV !== 'production') { //do stuff }
works as expected anywhere else in a vue app; however, it is not properly detecting the production string unless it also checks for double quotes when being read from the websocket-client node module.

from adonis-websocket-client.

reg2005 avatar reg2005 commented on May 21, 2024

Vue-CLI-3 is not build vendor libraries use it or it

from adonis-websocket-client.

RomainLanz avatar RomainLanz commented on May 21, 2024

Thanks for your comment @reg2005.

@nicktupy, it should work if you add this package to the transpileDependencies in your config.

from adonis-websocket-client.

nicktupy avatar nicktupy commented on May 21, 2024

Adding it to the transpileDependencies array appears to break the module for me.

from adonis-websocket-client.

RomainLanz avatar RomainLanz commented on May 21, 2024

Could you please create a repository with the minimum amount of code to reproduce the issue so I can have a look?

from adonis-websocket-client.

nicktupy avatar nicktupy commented on May 21, 2024

Here is a freshly generated vue project with the adonis-websocket-client installed via npm i @adonisjs/websocket-client

When launched via the Vue-CLI using the "Serve" task with the "Production" parameter selected or the "Build" task, you should see the websocket debug messages being written to the console.

Uninstalling @adonisjs/websocket-client and installing it via my modified fork of it will demonstrate the fix.
npm install https://github.com/nicktupy/adonis-websocket-client

from adonis-websocket-client.

RomainLanz avatar RomainLanz commented on May 21, 2024

Your repository doesn't exist @nicktupy.

from adonis-websocket-client.

nicktupy avatar nicktupy commented on May 21, 2024

Sorry, I accidentally created it as a private repo. It should be public now.

from adonis-websocket-client.

Mcdostone avatar Mcdostone commented on May 21, 2024

I have the same issue, impossible to disable console output even if with a definePlugin configured. I'm not using vueCLI but webpack CLI (webpack ^4.28.4, webpack-cli ^3.2.1)

The command I use: webpack --mode production -p

const webpack = require('webpack')
const path = require('path')

module.exports = (_, options) => {
  return {
    target: 'web',
    entry: {
      'js/log': './resources/assets/scripts/log.js',
    output: {
      path: path.resolve('./public/')
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          loader: 'babel-loader',
          exclude: /node_modules/
        },
      ]
    },
    plugins: [
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify(options.mode),
      }),
    watch: options.mode !== 'production'
  }
}
// resources/assets/scripts/log.js
import 'babel-polyfill'
import Ws from '@adonisjs/websocket-client'
function subscribeToChannel (ws) {
  const log = ws.subscribe('log')
  // do some stuff
}

document.addEventListener('DOMContentLoaded', () => {
  const ws = Ws('', { reconnectionAttempts: 3, reconnection: false }).connect()
  ws.on('open', () => subscribeToChannel(ws))
  ws.on('error', err => console.error('error', err))
  window.onbeforeunload = () => {
    if (ws) {
      ws.close()
    }
  }
})

from adonis-websocket-client.

nicktupy avatar nicktupy commented on May 21, 2024

from adonis-websocket-client.

Skullcan avatar Skullcan commented on May 21, 2024

Having same issue with React.

from adonis-websocket-client.

vanessa avatar vanessa commented on May 21, 2024

I'm having the same problem with React as well. Using @nicktupy's solution solved the problem for me.

from adonis-websocket-client.

FatihKaanAkkus avatar FatihKaanAkkus commented on May 21, 2024

I have the same issue with the [email protected] using @adonisjs/[email protected]. All the configuration is coming from the examples on the documentation 4.1.0. For the given information and the package itself it should work with the NODE_ENV set as "production".

Also in the "dist/Ws.browser.js" implementation NODE_ENV check is missing. What is the reason behind it? It sure works with react environment, but I don't have enough knowledge for others to understand. Thank you.

var Debug = createCommonjsModule(function (module) {

  /*
   * adonis-websocket-client
   *
   * (c) Harminder Virk <[email protected]>
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
  */

  {
    var _Debug = browser;
    _Debug.enable('adonis:*');
    module.exports = _Debug('adonis:websocket');
  }
});

Changing above to add a condition to check if process.env.NODE_ENV !== 'production' fixes my problem.

PS Permalink link to source for non-browser setup:

if (process.env.NODE_ENV !== 'production') {

from adonis-websocket-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.