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

ci-info module throw error for "process is not defined" #19

Closed
tim-yao opened this Issue May 24, 2018 — with CMTY · 9 comments

Comments

Projects
None yet
9 participants

tim-yao commented May 24, 2018 — with CMTY

Version

1.3.0

Reproduction link

https://codepen.io/timyaodpc/pen/bMyazm

Steps to reproduce

Use it in Nuxt/plugins/myplugin.js.

It all works but in browser console it give me a error says "process is not defined". Error points to "ci-info" module first line which tries to use process.env.

I can see ci-info is a dependency of consola as below:

└─┬ consola@1.3.0
└─┬ std-env@1.3.0
└─┬ is-ci@1.1.0
└── ci-info@1.1.3

I now have to add isServer condition on const consola = require('consola'). Otherwise it breaks the client side.

What is expected ?

Browser should no error in console.

What is actually happening?

A error from ci-info says "process is not defined".

index.js:3 Uncaught ReferenceError: process is not defined
at Object../node_modules/ci-info/index.js (index.js:3)
at webpack_require (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)
at Object../node_modules/is-ci/index.js (index.js:3)
at webpack_require (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)
at Object. (index.js:1)
at Object../node_modules/std-env/index.js (index.js:18)
at webpack_require (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)

Additional comments?

Is Consola can only be used in server side js?
The consola code index.js first line imported std-env which can only used in server side.
https://github.com/nuxt/consola/blob/master/src/index.js#L1
Not sure which is the best way to use it in Nuxt and maybe it's a bug?

This bug report is available on Nuxt.js community (#c32)

@cmty cmty bot added the cmty:bug-report label May 24, 2018

@Mucaccino

This comment has been minimized.

Mucaccino commented Jun 13, 2018

How about that? The same on 1.4.1 version.

@benfavre

This comment has been minimized.

benfavre commented Jun 13, 2018

Same on nuxt-edge.

Would like to see someone release a wrapper plugin/module for nuxt with server side only loging function and client side only or both, and a flag to ajust logging level based on node_env.

Great work so far. Thanks !

@PhouvanhKCSV

This comment has been minimized.

PhouvanhKCSV commented Jun 25, 2018

Any updates on this?, i got this problem too. Nuxt 1.4.1

@clarkdo

This comment has been minimized.

Member

clarkdo commented Jun 26, 2018

@tim-yao
The current Consola is indeed a logger for Node.js, so it's not supported in client side.

@benfavre
Maybe it's not very appropriate to add a plugin or module, because that codes cannot be optimized in client building.

I suggest to use process.server in Nuxt to wrap the logging codes, for example:

if(process.server) {
  Consola.log('this block will be removed in client side by webpack')
}

/cc @pi0

@tim-yao

This comment has been minimized.

tim-yao commented Jun 28, 2018

Thanks @clarkdo As it is not suppose to be used in Node.js only, I will close this issue now. But maybe worth to add some description in Readme.

@tim-yao tim-yao closed this Jun 28, 2018

This comment has been minimized.

SalvadorDuran commented Aug 6, 2018 — with CMTY

I'm having the same issue right now since I yarn upgrade to the last version of nuxt. I'm not using consola... Any solution?

@marcDeSantis

This comment has been minimized.

marcDeSantis commented Oct 23, 2018

Are there plans for addressing this? I don't see how consola is meant to be used with this bug in place.

@pi0

This comment has been minimized.

Member

pi0 commented Nov 2, 2018

Official browser support has arrived with v2.0.0. It only takes 1.5KB / Gzipped for the browser.

@pi0 pi0 closed this Nov 2, 2018

@manniL

This comment has been minimized.

Member

manniL commented Nov 2, 2018

image
❤️

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