Repository consola

manniL

manniL posted a new feature request

consola • 10 days ago

idea docs: improve mocking guide

What problem does this feature solve?

It'd be great to have a few examples on how to mock consola (default, but also withScope) ☺️

We already have examples in the README, but a few more words to each wouldn't be bad ☺️

pimlie

pimlie posted a new question

consola • a month ago

How to use custom consola instance with nuxt (probably esm/cjs issue)

Although the docs say that consola is a global object, I cant get it too work correctly it seems. I have narrowed it down to module.exports which are cached.

<summary>A basic example is this</summary>

// run as <file>.js
const { Consola, FancyReporter } = require('consola')

consola = new Consola({
  level: 4,
  reporters: [ new FancyReporter ],
  types: {
    warn: {
      level: 2,
      color: 'blue'
    },
  }
})

global.consola = consola

const consola2 = require('consola')
consola2.warn('yellow warning about nothing')

delete require.cache[require.resolve('consola')]

const consola3 = require('consola')
consola3.warn('blue warning about nothing')

The last consola3.warn is only blue when you delete the require.cache. This is because the first require already triggered node to cache the consola module, and as all other requires resolve to the same module/file it just uses the cached file.

The problem comes with esm modules like Nuxt has, the delete require.cache doesnt work there because during transpiling all requires are moved to the top of the file. Besides that, the delete require.cache trick only works when exactly:

  • the delete happens after the custom global.consola assigment
  • the require of Nuxt also happens after the custom global.consola assigment (and after the delete ofc)

<summary>Require Nuxt works (both lines blue)</summary>

// run with node -r esm <file.js>
console.log('mix -> works')
import consola from './inc/consola'
delete require.cache[require.resolve('consola')]

const { Nuxt } = require('nuxt')
const nuxt = new Nuxt()
nuxt.hook('render:context', () => {})
consola.warn('blue warning about nothing')

The following doesnt work:

<summary>Import Nuxt doesnt work (Nuxt's warning is yellow but should be blue)</summary>

// run with node -r esm <file.js>
import consola from './inc/consola'
delete require.cache[require.resolve('consola')]
import { Nuxt } from 'nuxt'

const nuxt = new Nuxt()
nuxt.hook('render:context', () => {})
consola.warn('blue warning about nothing')

<summary>inc/consola.js</summary>

import { Consola, FancyReporter } from 'consola'

let consola = global && global.consola

if (!consola) {
  consola = new Consola({
    level: 4,
    types: {
      warn: {
        level: 2,
        color: 'blue'
      },
    }
  })

  consola.add(new MyReporter())

  global.consola = consola
}

export default consola

Is it just too late and am I missing something obvious here? Any help / pointers are appreciated :)

Fyi, I am looking into this because for nuxt-generate-cluster I want all workers to push their log messages to the master so only the master has logging output. This does work nicely with a custom reporter, but I cant seem to capture the success: Generated /users/2 messages from within Nuxt.Generator. At least not without dirty tricks like re-assigning all object props again tp the global.consola object and stubbing the success method.

kazumi-kondo-forgevision

kazumi-kondo-forgevision posted a new question

consola • 2 months ago

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

please reopen this issue.
https://github.com/nuxt/consola/issues/19


"@nuxtjs/axios": {

"version": "5.3.1",

"consola": {

"version": "1.4.1",

"std-env": {

"version": "1.3.1",

"is-ci": {

"version": "1.1.0",

"ci-info": {

"version": "1.1.3",

abegehr

abegehr posted a new question

consola • 2 months ago

Can consola be used in components?

I'm using consola in a component by importing directly after the script-tag:

<script>
const consola = require("consola");
…

And then I use consola.start("Starting"); later on in a method.

I get the following error:

client.js:533 [nuxt] Error while initializing app ReferenceError: process is not defined
at Object../nodemodules/ci-info/index.js (index.js:3) at webpackrequire (bootstrap 9ce993297b8f99b86341:712)
at fn (bootstrap 9ce993297b8f99b86341:117)
at Object../nodemodules/is-ci/index.js (index.js:3) at webpackrequire (bootstrap 9ce993297b8f99b86341:712)
at fn (bootstrap 9ce993297b8f99b86341:117)
at Object.<anonymous> (index.js:1)
at Object../nodemodules/std-env/index.js (index.js:18) at webpackrequire (bootstrap 9ce993297b8f99b86341:712)
at fn (bootstrap 9ce993297b8f99b86341:117)

tim-yao

tim-yao posted a new bug report

consola • 5 months ago

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

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:

└─┬ [email protected]
└─┬ [email protected]
└─┬ [email protected]
└── [email protected]

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../nodemodules/ci-info/index.js (index.js:3) at webpackrequire (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)
at Object../nodemodules/is-ci/index.js (index.js:3) at webpackrequire (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)
at Object.<anonymous> (index.js:1)
at Object../nodemodules/std-env/index.js (index.js:18) at webpackrequire (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?

nikolaynesov

nikolaynesov posted a new question

consola • 5 months ago

Please remove the issue

Please remove it

hqqxxf

hqqxxf posted a new bug report

consola • 5 months ago

bug The page returned to the home page on wechat

Version

1.4.0

Reproduction link

https://jsfiddle.net/hqqxxf/edLsh8sL/

Steps to reproduce

in router '/a', it has a link to '/b', when I returned in '/b', The page returned to the home page('/') , and I found not the static resources request when returned.

What is expected ?

returned to the last page(router '/a')

What is actually happening?

returned to the home page(router '/' or 404)

ujjwalguptaofficial

ujjwalguptaofficial posted a new question

consola • 5 months ago

override route based on the pages folder

Let say In pages folder I have two folder - temp1 and temp2. So url will be -

"localhost/temp1/" and "localhost/temp2/ "

I want to overload url for temp2 folder and make it like - "localhost/" . I mean make it like the content of temp2 folder is in root

chenfangyi931

chenfangyi931 posted a new question

consola • 6 months ago

The vuex state can not be modified within the Axios interceptor

TIM截图20180506183037.png

kuangyazhou

kuangyazhou posted a new question

consola • 6 months ago

asyncData how to send multi request

in my code

async asyncData(){
const [a,b]=await Promise.all( await axios.get('/api/users'), await axios.get('/api/list') )
return {
users:a,
list:b,
}
}

why this mehtod not work ??
In my view ,i won't get the data users and list

what is the right writing

Jeromearsene

Jeromearsene posted a new question

consola • 6 months ago

Object is undefined if not stringified (JSON.stringify)

I have an object to log.

I do this:

    console.log(professionnalInfos);
    logger.info(professionnalInfos);
    logger.info(JSON.stringify(professionnalInfos));

Result:

{ siren: '1111111', phone: '0511111111' }
ℹ info undefined
ℹ info {"siren":"1111111","phone":"0511111111"}

I think undefined is counter intuitive. No ?

kuangyazhou

kuangyazhou posted a new question

consola • 6 months ago

how can i debugger my code in development

now ,i'm useing the nuxt-express templte 。in chrome ,i open the network ,how can I debugger my code by the method set point

Jeromearsene

Jeromearsene posted a new question

consola • 6 months ago

Problem error log color invisible

With my iterm configuration, I have this problem:
capture d ecran 2018-05-03 a 11 01 05

Error's details exist. If I select details, you can see this:
capture d ecran 2018-05-03 a 11 01 19

An idea for custom color ? Or other idea who can help me.

Thank you

Extarys

Extarys posted a new question

consola • 6 months ago

How can I access the innerText property of an element inside a component?

EDIT: Definitely not the right category, should be in Nuxt not consola. Sorry.

I'm trying to make a div with contenteditable and I need to set the innerText property. (I saw something on a chinese website, said it works)

My editable.vue component:

<template>
  <div
    contenteditable="true"
    @input="update"></div>
</template>
<script>
export default {
    props: {
        content: {
            type: String,
            default: '',
        },
    },
    mounted: () => {
        this.$el.innerText = this.content;
    },
    methods: {
        update (event) {
            this.$emit('update', event.target.innerText);
        },
    },
};
</script>

I'm calling it with <editable @update="editableRaw = $event"></editable>

I need a div to include emoji based on images, since most browsers don't support the latest always and I want it to be uniform.

Hope someone can enlighten me.
Cheers

acaxon

acaxon posted a new question

consola • 6 months ago

How can I pass a class (ES6) to a module?

In my Nuxt application I created a folder called models, and inside it I have some js files, each one defining a class that extends MyModel - a base class that is defined in an external module - my-module.

In nuxt.config.js I have:


modules: [
'my-module/nuxt'
],

I need to pass these extended classes to that module. How can I do this?

Thanks in advance.

pontakornth

pontakornth posted a new question

consola • 6 months ago

Vuex state is disappeared when route changed

Why Vuex state disappear whenever I change routes. My state is an array that contain blog posts. It works fine when I added post in index page using actions. Initial state is array of single post with ID of 0 like this [{id:0,title:"Problem is",content:"here"}], actions works and the array is pushed.

But when I change route the state is reversed to initial state again.

Heziode

Heziode resolved the question #c19

consola • 6 months ago

Generation Error: Cannot detect env, something went wrong!

The problem seems be solved by adding mode: 'spa' into nuxt.config.js

juppdes

juppdes posted a new bug report

consola • 6 months ago

bug [edge] css file´s path builded wrong

Version

Edge

Reproduction link

https://jsfiddle.net/Jupp/adnsv7ef/3/

Steps to reproduce

The background file set in the css is searched at 'http://localhost:3333/static/any.jpg', when it should be searched at 'http://localhost:3333/_nuxt/img/any.jpg'

What is expected ?

That point correctly to the files set in css classes.

What is actually happening?

I think they are looking for the wrong place.

Heziode

Heziode posted a new question

consola • 6 months ago

Generation Error: Cannot detect env, something went wrong!

Hi, when I try to generate static site, I get this error: "Error: Cannot detect env, something went wrong!"

yarn run generate
yarn run v1.6.0
$ nuxt generate
  nuxt:generate Generating... +0ms
  nuxt:build App root: FOE/foe-tools_V2 +0ms
  nuxt:build Generating FOE/foe-tools_V2/.nuxt files... +0ms
  nuxt:build Generating files... +11ms
  nuxt:build Generating routes... +35ms
  nuxt:build Building files... +49ms
  ████████████████████ 100% 

Build completed in 25.529s



 WARNING  Compiled with 1 warnings                                            02:28:05

 warning  

asset size limit: The following asset(s) exceed the recommended size limit (300 kB).
This can impact web performance.
Assets: 
  pages/gb-statistics.bcd8ddc88801f8ad587d.js (461 kB)
  pages/_root/gb-statistics/index.e336a94a36ec7db6e379.js (461 kB)
  pages/_root/gb-statistics/script.7d70a27517666c7ec160.js (454 kB)
  vendor.cceecb3e551f4fabeb44.js (442 kB)
  app.4910bd7a19744598e419.js (316 kB)

Hash: 4ea10b662f86cdce7c57
Version: webpack 3.11.0
Time: 25535ms
                                                     Asset       Size  Chunks                    Chunk Names
           layouts/_default/script.37f72315177a6d69e96b.js    4.23 kB      16  [emitted]         layouts/_default/script
                   pages/changelog.e07cab1bd7bc3f814013.js     124 kB    0, 1  [emitted]         pages/changelog
      pages/_root/changelog/script.65c5c23a90f2de3ecde1.js     123 kB       2  [emitted]         pages/_root/changelog/script
               pages/gb-statistics.bcd8ddc88801f8ad587d.js     461 kB    3, 4  [emitted]  [big]  pages/gb-statistics
   pages/_root/gb-statistics/index.e336a94a36ec7db6e379.js     461 kB       4  [emitted]  [big]  pages/_root/gb-statistics/index
  pages/_root/gb-statistics/script.7d70a27517666c7ec160.js     454 kB       5  [emitted]  [big]  pages/_root/gb-statistics/script
     pages/gb-investment/_gb/index.816e261a27ff58435a36.js    59.2 kB       6  [emitted]         pages/gb-investment/_gb/index
    pages/gb-investment/_gb/script.6fe76ae5b5f16ce41e6a.js    58.8 kB       7  [emitted]         pages/gb-investment/_gb/script
                   layouts/default.a93d2a55540ae08d9e7a.js     165 kB    8, 9  [emitted]         layouts/default
            layouts/_default/index.2705bf27b1459994a905.js     165 kB       9  [emitted]         layouts/_default/index
             pages/secure-position.552cdeb18e55b166be71.js    10.6 kB  10, 11  [emitted]         pages/secure-position
 pages/_root/secure-position/index.45d456cc0d38c605591f.js    10.3 kB      11  [emitted]         pages/_root/secure-position/index
               pages/cf-calculator.b3594828faf533013d3e.js    17.8 kB  12, 17  [emitted]         pages/cf-calculator
                       pages/index.0d2c5e46beb58f0f7171.js    1.87 kB  13, 20  [emitted]         pages/index
                pages/contributors.6dd30851422e440e45de.js    3.68 kB  14, 21  [emitted]         pages/contributors
                       pages/about.f9f3fa179314f39f0f24.js    2.04 kB  15, 22  [emitted]         pages/about
       pages/_root/changelog/index.724d516410a6a5e3ba67.js     123 kB       1  [emitted]         pages/_root/changelog/index
   pages/_root/cf-calculator/index.fa405889e367623a1def.js    17.5 kB      17  [emitted]         pages/_root/cf-calculator/index
         pages/gb-investment/index.47e1345d6f69ba85e3a5.js    34.3 kB      18  [emitted]         pages/gb-investment/index
pages/_root/secure-position/script.e9f6c6040e0338e713ce.js    9.94 kB      19  [emitted]         pages/_root/secure-position/script
            pages/_root/home/index.af5662f0aa052a3577cd.js    1.61 kB      20  [emitted]         pages/_root/home/index
    pages/_root/contributors/index.ee2b1ddbe6c670ea946f.js    3.41 kB      21  [emitted]         pages/_root/contributors/index
           pages/_root/about/index.98789df8a402517d1a96.js    1.78 kB      22  [emitted]         pages/_root/about/index
        pages/gb-investment/script.b3a7b95b81bbaaa212a1.js    33.4 kB      23  [emitted]         pages/gb-investment/script
  pages/_root/cf-calculator/script.1e7be91bd8a2fa54addc.js    8.98 kB      24  [emitted]         pages/_root/cf-calculator/script
           pages/_root/home/script.83a64a5e91da46f91d87.js  788 bytes      25  [emitted]         pages/_root/home/script
   pages/_root/contributors/script.fb592aca202be31e1999.js  873 bytes      26  [emitted]         pages/_root/contributors/script
          pages/_root/about/script.6c55ce9365dc6268b272.js  319 bytes      27  [emitted]         pages/_root/about/script
             layouts/_error/script.fe9d38506427f2ac22d6.js  763 bytes      28  [emitted]         layouts/_error/script
                            vendor.cceecb3e551f4fabeb44.js     442 kB      29  [emitted]  [big]  vendor
                               app.4910bd7a19744598e419.js     316 kB      30  [emitted]  [big]  app
                          manifest.4ea10b662f86cdce7c57.js       3 kB      31  [emitted]         manifest
                                                  LICENSES    5.22 kB          [emitted]         
 + 3 hidden assets

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (300 kB).
This can impact web performance.
Assets: 
  pages/gb-statistics.bcd8ddc88801f8ad587d.js (461 kB)
  pages/_root/gb-statistics/index.e336a94a36ec7db6e379.js (461 kB)
  pages/_root/gb-statistics/script.7d70a27517666c7ec160.js (454 kB)
  vendor.cceecb3e551f4fabeb44.js (442 kB)
  app.4910bd7a19744598e419.js (316 kB)
Hash: 58ddd684a04d05137b9b
Version: webpack 3.11.0
Time: 4164ms
             Asset     Size  Chunks             Chunk Names
server-bundle.json  1.76 MB          [emitted]  
  nuxt: Call generate:distRemoved hooks (1) +0ms
  nuxt:generate Destination folder cleaned +30s
  nuxt: Call generate:distCopied hooks (1) +13ms
  nuxt:generate Static & build files copied +13ms
  nuxt:render Rendering url /secure-position +0ms
  nuxt:render Rendering url /about +105ms
  nuxt:render Rendering url /changelog +1ms
  nuxt:render Rendering url /contributors +1ms
  nuxt:render Rendering url /gb-statistics +1ms
  nuxt:render Rendering url /cf-calculator +4ms
  nuxt:render Rendering url /gb-investment +1ms
  nuxt:render Rendering url /gb-investment/script +4ms
  nuxt:render Rendering url / +3ms
  nuxt:render Rendering url / +112ms
  nuxt: Call generate:done hooks (1) +238ms
  nuxt:generate HTML Files generated in 30.4s +238ms

 Generate errors summary:

 ROUTE  /secure-position

  Error: Cannot detect env, something went wrong!

 ROUTE  /about

  Error: Cannot detect env, something went wrong!

 ROUTE  /changelog

  Error: Cannot detect env, something went wrong!

 ROUTE  /contributors

  Error: Cannot detect env, something went wrong!

 ROUTE  /gb-statistics

  Error: Cannot detect env, something went wrong!

 ROUTE  /cf-calculator

  Error: Cannot detect env, something went wrong!

 ROUTE  /gb-investment

  Error: Cannot detect env, something went wrong!

 ROUTE  /gb-investment/script

  Error: Cannot detect env, something went wrong!

 ROUTE  /

  Error: Cannot detect env, something went wrong!

  nuxt:generate Generate done +11ms
Done in 31.43s.

Anybody have a solution to fix this ?

jasonc08

jasonc08 posted a new question

consola • 6 months ago

Deleted

Sorry, I post the question in a wrong place. Please help me delete it.