Open gbenson-ir opened 1 year ago
I am also experiencing this issue and cannot upgrade because of this
Same issue here. Any idea?
I worked around it by mocking Consola in the tests, maybe it helps someone:
jest.config.js
module.exports = {
moduleNameMapper: {
consola: "<rootDir>/test/unit/test-utils/mockConsola.js"
}
};
mockConsola.js
// mocking because of incompatibility between consola v3 & jest, see https://github.com/unjs/consola/issues/195
const LogTypes = [
"silent",
"fatal",
"error",
"warn",
"log",
"info",
"success",
"fail",
"ready",
"start",
"box",
"debug",
"trace",
"verbose",
];
class Consola {
constructor() {
const types = LogTypes;
LogTypes.forEach((type) => {
this[type] = function () {
if (["error", "warn"].includes(type)) console[type](...arguments);
};
});
}
mockTypes(mockFn) {
LogTypes.forEach((type) => {
this[type] = mockFn(type);
});
}
create() {
return new Consola();
}
}
const createConsola = function () {
return new Consola();
};
const consola = createConsola();
export { consola, createConsola };
Basically it mutes all consola logs except of warn and error which are printed via native console.
Maybe related: I'm also having issues using consola v3 with Nuxt2 + Nuxt Bridge. Dev mode works fine, building as well. But when I run nuxi start
, I get:
│ You are running Nuxt production build in preview mode.
│ Node.js: v18.14.2
│ Nitro Preset: node-server
│ Working directory: .output
Listening on http://0.0.0.0:3000
[nuxt] [request error] [unhandled] [500] Object(...) is not a function
at ./server/chunks/app/server.mjs:41322:67
at callWithNuxt (./server/chunks/app/server.mjs:10259:25)
at ./server/chunks/app/server.mjs:10264:31
at createApp (./server/chunks/app/server.mjs:41692:16)
at async __webpack_exports__.default (./server/chunks/app/server.mjs:41820:12)
at async Object.renderToString (./server/chunks/handlers/renderer.mjs:216:19)
at async ./server/chunks/handlers/renderer.mjs:657:21
at async ./server/chunks/handlers/renderer.mjs:18:22
at async Object.handler (./server/chunks/nitro/node-server.mjs:2006:19)
at async Server.toNodeHandle (./server/chunks/nitro/node-server.mjs:2195:7)
which points to the line where I call createConsola()
.
It's because package.json["exports.default"]
was missing an entry for require
for jest to correctly resolve it:
"require": "./dist/browser.cjs"
Now it's in repo but not released yet. @pi0 is it possible to release the fix?
Environment
Node v18.15.0 NPM v8.19.2 Consola v3.1.0
Reproduction
npm i
npm run test
Describe the bug
Since upgrading to v3 of consola, I am unable to run my unit tests. My tests fail and I receive the error "Cannot find module 'consola'".
This happens whether or not I use the new named exports.
Upgrading consola is the only change I have made to my project; before the upgrade I did not have the issue, following the upgrade I do. Prior to the upgrade I was using consola v2.15.3.
Additional context
I'm using Jest to run my unit tests. In my actual project I'm using TypeScript, but in the repo linked above it's a simple javascript project that also uses Jest (and babel-jest to transform the JS) and the issue is still present.
Logs