Decorator issue
Having a weird issue with the decorators..
I've just updated all of my dependencies to the absolute latest version, but the error is still persisting here. It seems to be quite random, but there are steps I can take every time to get the error.
Note that I've always had
"experimentalDecorators": true,
as part of my tsconfig - everything I've seen so far suggests adding that.
When I remove "experimentalDecorators": true,
, the same error appears across every file, not just the one file with the issue.
Notably, when I see the issue, I also have a bunch of other errors (pointing to the discord.js package inside nodemodules, something about ECMAScript 2015, and a whole bunch of errors across other files that aren't normally there.
Also, the project compiles fine, the decorator throwing the issue is working as expecred, but the whole project is going mental with errors that it's never reported before.
To reproduce this, I;
- Copy an existing file
- Rename the file/class name
Then, I see the error reported on the decorator,
Then, several other errors appear
5 Replies
Works without issue,
reports the error
Works without issue, no error reported
These errors are only reported when I have the file open that has the decorator error
Also to add, I've also tried clearing out the dist, node modules, and package lock
In TypeScript v5 the TypeScript developers shipped initial support for the upcoming Decorators proposal for JavaScript. This means that by default TypeScript will allow the usages of decorators in your TypeScript code, unlike before where it would throw an error when doing so without proper configuration. This is a pitfal however, as many libraries, including @sapphire/decorators, are not yet updated to use the new decorators proposal. This means that you will have to enable the experimental decorators in your
tsconfig.json
file. To do so, add the following to your tsconfig.json
file:
@Boomeravna As mentioned, I already have this enabled
This is my tsconfig, I've been using experimentalDecorators for quite a while, at least 18mo, probably longer (not at pc to check exact)
try setting your moduleResolution to node16
the default when module is set to commonjs is
'node10' (previously called 'node') for Node.js versions older than v10, which only support CommonJS require. You probably won’t need to use node10 in modern code.see https://www.typescriptlang.org/tsconfig/#moduleResolution