[SOLVED] ts-node cannot find npm module discord-api-types


When attempting to run discord.js file deploy-commands.ts with the command ts-node deploy-commands.ts ts-node produces the following error:

Error: Cannot find module 'discord.js/node_modules/discord-api-types'
Require stack:
- /Users/Cameron/discord.js/discordjs-guides/deploy-commands.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/usr/local/lib/node_modules/ts-node/node_modules/@cspotcode/source-map-support/source-map-support.js:679:30)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/Cameron/discord.js/discordjs-guides/deploy-commands.ts:4:1)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1455:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1458:12) {
  requireStack: [ '/Users/Cameron/discord.js/discordjs-guides/deploy-commands.ts' ]

Despite discord-api-types appearing both in the node-modules folder and in package.json. The error is consistently reproduced after running npm install discord-api-types and npm resoding discord-api-types is up-to-date.

Package.json dependencies:

"dependencies": {
    "@discordjs/builders": "^0.12.0",
    "@discordjs/rest": "^0.3.0",
    "discord-api-types": "^0.29.0",
    "discord.js": "^13.6.0",
    "dotenv": "^16.0.0",
    "nodemon": "^2.0.15",
    "ts-node": "^10.7.0"


import { SlashCommandBuilder } from "@discordjs/builders";
import { REST } from "@discordjs/rest";
import { version } from "discord.js";
import { Routes } from "discord.js/node_modules/discord-api-types";

const { token, guildID, clientID } = require('./process.json')

const commands = [
    new SlashCommandBuilder().setName('ping').setDescription('Replies with pong.'),
    new SlashCommandBuilder().setName('server').setDescription('Replies with server info.'),
    new SlashCommandBuilder().setName('user').setDescription('Replies with user info.'),
    .map(commands => JSON)

const rest = new REST({version: '9'}).setToken(token)

rest.put(Routes.applicationCommand(clientID, guildID), {body: { commands }})
    .then(() => {
        console.log('Successfully registered application commands')


I think you need to change this code line:

import { Routes } from "discord.js/node_modules/discord-api-types";

To its version using because of this:

const rest = new REST({version: '9'}).setToken(token)

So you need to define the version you use, try changing your import to

import { Routes } from "discord-api-types/v9";

As I tried to my testing slash command files, you can do this kind of line too:

import { Routes } from "discord.js/node_modules/discord-api-types/v9";

I’m not using .ts so might not work but give it a shot

Answered By – æ–°Acesyyy

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *