pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
MIT License
2.61k stars 157 forks source link

Cannot set property trace of #<Object> which has only a getter #196

Closed designamx closed 9 months ago

designamx commented 9 months ago

starting today we are getting this error

[ERROR] 14:32:05 TypeError: Cannot set property trace of #<Object> which has only a getter
TypeError: Cannot set property trace of #<Object> which has only a getter
api.apt.local     |     at Object.replaceLoggingMethods (/usr/src/node_modules/loglevel/lib/loglevel.js:96:30)
api.apt.local     |     at Object.Logger.self.setLevel (/usr/src/node_modules/loglevel/lib/loglevel.js:267:40)
api.apt.local     |     at Object.<anonymous> (/usr/src/api/src/config/logger.ts:6:8)
api.apt.local     |     at Module._compile (node:internal/modules/cjs/loader:1241:14)
api.apt.local     |     at Module._compile (/usr/src/node_modules/source-map-support/source-map-support.js:568:25)
api.apt.local     |     at Module.m._compile (/tmp/ts-node-dev-hook-024130929438604287.js:69:33)
api.apt.local     |     at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
api.apt.local     |     at require.extensions..jsx.require.extensions..js (/tmp/ts-node-dev-hook-024130929438604287.js:114:20)
api.apt.local     |     at require.extensions.<computed> (/tmp/ts-node-dev-hook-024130929438604287.js:71:20)
api.apt.local     |     at Object.nodeDevHook [as .ts] (/usr/src/node_modules/ts-node-dev/lib/hook.js:63:13)

Node: node:20.6.1-alpine3.17 also tested node:20.10.0-alpine3.17

itsjbecks commented 9 months ago

Also been having this issue on Node.js v20.11.0 and v18.14.2 (very recently)

pimterry commented 9 months ago

This must be related to the v1.9.0 version just released - you can downgrade to v1.8.1 to avoid this.

Can you provide a standalone example to reproduce the issue though? I'm not sure exactly what would cause this.

designamx commented 9 months ago

@pimterry thanks, that was it

pimterry commented 9 months ago

@designamx this is clearly still an issue in the package, but glad to know the downgrade resolves this for you.

Can you please share an example to help reproduce this, or any more information you can about how you're using loglevel? Otherwise this isn't going to be resolved in future releases of the package and so you'll just hit the same issue again later on.

designamx commented 9 months ago

sure, I can do that

designamx commented 9 months ago

I have placed a small docker project, to replicate you just need to docker build -t logleveldebug . and then docker run logleveldebug or just yarn and then yarn start

Repo

Please let me know if there is anything else I can help with

pimterry commented 9 months ago

Thanks @designamx, that's perfect.

Looks like it's something to do with ts-node-dev's ESM emulation, which treats the exported properties as unmodifiable. That is true for pure ESM modules, but this package isn't actually ESM at all, I think it's just that the runtime is effectively emulating that.

You can fix this failure in the current version by importing with import Logger from 'loglevel' instead of import * as Logger from 'loglevel'. That will avoid this bug but otherwise behave exactly the same.

That said, I think I know what's caused the underlying issue in this case, so it should be easy enough to fix properly so everything works in the previous syntax too. I'll dig into that and release a fully fixed update shortly.

pimterry commented 9 months ago

Now fixed in v1.9.1.

I've tested in the above repo and using the latest package version everything once again works correctly with no changes required to imports or anything else.

I'm going to close this now as resolved, but please shout if anybody is still seeing this issue elsewhere.