Comments (15)
Hey @nicktupy! 👋
'production'
or "production"
are exactly the same, they are both strings.
from adonis-websocket-client.
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.
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.
Vue-CLI-3 is not build vendor libraries use it or it
from adonis-websocket-client.
Thanks for your comment @reg2005.
@nicktupy, it should work if you add this package to the transpileDependencies
in your config.
from adonis-websocket-client.
Adding it to the transpileDependencies array appears to break the module for me.
from adonis-websocket-client.
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.
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.
Your repository doesn't exist @nicktupy.
from adonis-websocket-client.
Sorry, I accidentally created it as a private repo. It should be public now.
from adonis-websocket-client.
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.
from adonis-websocket-client.
Having same issue with React.
from adonis-websocket-client.
I'm having the same problem with React as well. Using @nicktupy's solution solved the problem for me.
from adonis-websocket-client.
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:
from adonis-websocket-client.
Related Issues (20)
- adonis-websocket-vue repo not found HOT 10
- Websocket Connection to url failed HOT 1
- undefined is not an object (evaluation 'window.location.protocol') HOT 4
- How config TIMEOUT into options for ERROR on React Native Android HOT 2
- Disable console logs HOT 4
- Build
- Is that possible to adapt for React Native? HOT 1
- Unexpected token error when trying to import 'Ws' HOT 1
- Websocket Babel Error Fix
- Unsubscribing from channel HOT 1
- How to use websocket with flutter HOT 3
- Adonis WebSocket Client Example HOT 3
- How to use this library with react native? HOT 10
- Trying to close a channel and subscribing to it after throws an error HOT 1
- Access-Control-Allow-Origin
- ws.connect is not a functio HOT 1
- WebSocket client for NodeJS HOT 1
- How to close debug messages in desired env. Not just for production
- Use adonis-websocket-client with Web Worker
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adonis-websocket-client.