#mongoose / cannot find module ts

16 messages · Page 1 of 1 (latest)

uneven marsh
import { Message } from "discord.js";
import User from "../../lib/models/userModel";

export const messageTracker = async (message: Message) => {
  if (message.author.bot) return; 

  let user = await User.findOne({ guildId: message.guildId, userId: message.author.id });
  if (!user) {
    user = new User({
      guildId: message.guildId,
      userId: message.author.id,
    });
  }

  user.messageCount += 1;
  user.messageDay += 1;

  await user.save();
};

Error: Cannot find module 'E:\Bots\lunari\src\lib\models\userModel' imported from E:\Bots\lunari\src\events\trackers\messageTracker.ts
at finalizeResolution (E:\Bots\lunari\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:366:11)
at moduleResolve (E:\Bots\lunari\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:801:10)
at Object.defaultResolve (E:\Bots\lunari\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:912:11)
at E:\Bots\lunari\node_modules\ts-node\src\esm.ts:218:35
at entrypointFallback (E:\Bots\lunari\node_modules\ts-node\src\esm.ts:168:34)
at E:\Bots\lunari\node_modules\ts-node\src\esm.ts:217:14
at addShortCircuitFlag (E:\Bots\lunari\node_modules\ts-node\src\esm.ts:409:21)
at resolve (E:\Bots\lunari\node_modules\ts-node\src\esm.ts:197:12)
at nextResolve (node:internal/modules/esm/hooks:748:28)
at Hooks.resolve (node:internal/modules/esm/hooks:240:30)

Node.js v22.11.0

structure:

📦src
 ┣ 📂commands
 ┣ 📂events
 ┃ ┣ 📂trackers
 ┃ ┃ ┗ 📜messageTracker.ts
 ┃ ┗ 📜common.ts
 ┣ 📂guard
 ┣ 📂lib
 ┃ ┣ 📂jobs
 ┃ ┣ 📂models
 ┃ ┃ ┗ 📜userModel.ts
 ┃ ┗ 📜database.ts
 ┗ 📜main.ts
crimson bearBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
uneven marsh

What's wrong?

winged peak

can you try adding .js to it?

or .ts ig

uneven marsh

here?
import User from "../../lib/models/userModel";

winged peak

yes

uneven marsh

[{
"resource": "/E:/Bots/lunari/src/events/trackers/messageTracker.ts",
"owner": "typescript",
"code": "5097",
"severity": 8,
"message": "An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.",
"source": "ts",
"startLineNumber": 2,
"startColumn": 18,
"endLineNumber": 2,
"endColumn": 49
}]

winged peak

and .js?

uneven marsh

There’s no such thing with .js, but I’m on TS

winged peak

ts compiles to js though

you can't really import ts for that reason, ts will replace that with js

but they added that option with that tsconfig flag, otherwise it'll error

uneven marsh

I didn't quite understand

winged peak

did you read the ts handbook on how ts works?

uneven marsh

not completely