Skip to content
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

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

Closed
designamx opened this issue Jan 25, 2024 · 8 comments
Closed

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

designamx opened this issue Jan 25, 2024 · 8 comments

Comments

@designamx
Copy link

designamx commented Jan 25, 2024

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
Copy link

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

@pimterry
Copy link
Owner

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
Copy link
Author

@pimterry thanks, that was it

@pimterry pimterry reopened this Jan 25, 2024
@pimterry
Copy link
Owner

@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
Copy link
Author

sure, I can do that

@designamx
Copy link
Author

designamx commented Jan 25, 2024

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
Copy link
Owner

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
Copy link
Owner

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.

Mr0grog added a commit to Mr0grog/loglevel that referenced this issue Jan 26, 2024
We previously ran the `test/type-test.ts` test through the TypeScript compiler to catch type issues, but there are more subtle problems that can happen at runtime with tools like `ts-node` (and maybe things like Deno, too -- I haven't tested that). This additionally *runs* the test file to make sure it doesn't throw at runtime, which would have caught issues like pimterry#196 ahead of time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants