Issue
This Content is from Stack Overflow. Question asked by Kieran
I’ve got a discordJS (v14) bot that I’m starting (using typescript), and when I try to build it I get the following error:
node_modules/@sapphire/shapeshift/dist/index.d.ts:590:44 - error TS2344: Type 'T' does not satisfy the constraint 'object'.
590 declare type SchemaOf<T> = ObjectValidator<T>;
~
node_modules/@sapphire/shapeshift/dist/index.d.ts:590:23
590 declare type SchemaOf<T> = ObjectValidator<T>;
~
This type parameter might need an `extends object` constraint.
node_modules/@sapphire/shapeshift/dist/index.d.ts:641:65 - error TS2344: Type 'T' does not satisfy the constraint 'object'.
641 object<T>(shape: MappedObjectValidator<T>): ObjectValidator<T, UndefinedToOptional<T>>;
~
node_modules/@sapphire/shapeshift/dist/index.d.ts:641:12
641 object<T>(shape: MappedObjectValidator<T>): ObjectValidator<T, UndefinedToOptional<T>>;
~
This type parameter might need an `extends object` constraint.
Found 2 errors in the same file, starting at: node_modules/@sapphire/shapeshift/dist/index.d.ts:590
My index.ts looks like this (yes its basic, but trying to figure out this error)
import "dotenv/config";
import "reflect-metadata";
import { Client, GatewayIntentBits } from 'discord.js';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
]
});
client.login(process.env["DISCORD_TOKEN"]);
My package.json is:
{
"name": "my-discord-bot",
"version": "1.0.0",
"description": "My Discord Bot",
"main": "index.js",
"author": "myself",
"license": "MIT",
"private": true,
"type": "module",
"scripts": {
"cleanup": "rm -f -r ./dist/",
"build": "yarn cleanup && tsc",
"watch": "yarn cleanup && tsc -w",
"serve": "node ./dist/index.js",
"register": "node ./dist/register-commands.js",
"lint": "eslint . -ext .js,.jsx,.ts,.tsx",
"format": "prettier --write "./src/**/*.ts"",
"test": ""
},
"dependencies": {
"@sentry/integrations": "^7.13.0",
"@sentry/node": "^7.13.0",
"@sentry/tracing": "^7.13.0",
"anti-phish-advanced": "^1.1.0",
"axios": "^0.27.2",
"chrono-node": "^2.4.1",
"date-fns": "^2.29.3",
"discord.js": "^14.3.0",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"fuse.js": "^6.6.2",
"mysql2": "^2.3.3",
"reflect-metadata": "^0.1.13",
"steamid": "^2.0.0"
}
}
tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["types/*"]
},
"outDir": "./dist/",
"module": "es2020",
"target": "es2020",
// "lib": ["es2020"],
"moduleResolution": "node",
"noImplicitAny": false,
"allowJs": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"types": ["node", "reflect-metadata"],
"typeRoots": ["node_modules/@types"]
},
"include": ["./src/**/*"],
"exclude": ["**/node_modules", "**/__tests__/*", "**/tests/"]
}
A yarn why on the erroring package
yarn why v1.22.19
[1/4] Why do we have the module "@sapphire/shapeshift"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "@sapphire/shapeshift@3.5.1"
info Reasons this module exists
- "discord.js#@discordjs#builders" depends on it
- Hoisted from "discord.js#@discordjs#builders#@sapphire#shapeshift"
Does anyone know if there is anything that I’m doing that might be causing the issue? and how I might fix it? (short of just not using typescript)
Solution
https://github.com/sapphiredev/shapeshift/issues/193
Need to force resolution of the package to a higher version.
Using yarn (as I am) is easy, just add to package.json
resolutions: {
"@sapphire/shapeshift": "^3.6.0"
}
This Question was asked in StackOverflow by Kieran and Answered by Kieran It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.