gpt4 book ai didi

node.js - 内部/模块/cjs/loader.js :638 throw err; ^ Error: Cannot find module '../repositories/UserRepository' in docker container

转载 作者:行者123 更新时间:2023-12-04 19:28:34 57 4
gpt4 key购买 nike

它在 ubuntu 中出现。在托管网站时出现此错误。检查 docker 容器日志后,我能够看到此错误。但它在本地设备中运行..

internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module '../repositories/UserRepository'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/app/usr/src/services/user.services.js:2:24)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[nodemon] app crashed - waiting for file changes before starting.
我在检查容器日志时收到此错误。请帮我解决这个问题.. 我尝试了一些答案,例如 npm install,apt-get update 但所有这些对我都没有用..

最佳答案

像这样使用模块别名创建别名

moduleAlias.addAliases({
'@app': __dirname,
});
并像这样从别名导入这个文件
require('@app/path_to_directory/repositories/UserRepository)

关于node.js - 内部/模块/cjs/loader.js :638 throw err; ^ Error: Cannot find module '../repositories/UserRepository' in docker container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68887165/

57 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com