NodeJS 错误:找不到模块“@helpers/extenders/Message”

x8diyxa7  于 2023-03-22  发布在  Node.js
关注(0)|答案(1)|浏览(111)

安装了开源节点js discord bot。但突然,在设置配置后,我得到一个错误:

"C:\Program Files\nodejs\npm.cmd" run start

> discord-js-bot@5.2.0 start
> node .

node:internal/modules/cjs/loader:1024
  throw err;
  ^

Error: Cannot find module '@helpers/extenders/Message'
Require stack:
- D:\Programming\discord-js-bot\discord-js-bot\bot.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1021:15)
    at Function.Module._resolveFilename (D:\Programming\discord-js-bot\discord-js-bot\node_modules\module-alias\index.js:49:29)
    at Function.Module._load (node:internal/modules/cjs/loader:866:27)
    at Module.require (node:internal/modules/cjs/loader:1093:19)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (D:\Programming\discord-js-bot\discord-js-bot\bot.js:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1191:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10)
    at Module.load (node:internal/modules/cjs/loader:1069:32)
    at Function.Module._load (node:internal/modules/cjs/loader:904:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'D:\\Programming\\discord-js-bot\\discord-js-bot\\bot.js' ]
}

Process finished with exit code 1

它有jsconfig.json和这些:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "baseUrl": "./",
    "paths": {
      "@root/*": ["./*"],
      "@handlers/*": ["./src/handlers/*"],
      "@helpers/*": ["./src/helpers/*"],
      "@schemas/*": ["./src/database/schemas/*"],
      "@src/*": ["./src/*"],
      "@structures/*": ["./src/structures/*"]
    }
  },
  "exclude": ["node_modules", "**/node_modules/*"]
}

所有这些文件都存在。
所以我试了

npm cache clean –force
rm package-lock.json
rm -r node_modules
npm i --save --legacy-peer-deps

以及
npm link package_name
尝试完全重新安装此

这些尝试都没有成功

经过所有的尝试,我得到了同样的错误,我把在开始

w8f9ii69

w8f9ii691#

好吧...
它帮助我将jsconfig.js中的一部分添加到package.js中

"_moduleAliases" : {
     "@root" : ".",
     "@handlers" : "src/handlers",
     "@helpers" : "src/helpers",
     "@schemas" : "src/database/schemas",
     "@src" : "src",
     "@structures" : "src/structures"
   }

相关问题