您好,在 node.js 项目中,我无法将文件移动到 src 文件夹,因为运行节点文件时出错现在文件在根目录中

问题描述

错误:找不到模块“/Users/alejandraola/Documents/GitHub/SCL16-md-link/prueba.js” 在 Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15) 在 Function.Module._load (node:internal/modules/cjs/loader:769:27) 在 Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) 在节点:内部/主要/run_main_module:17:47 { 代码:'MODULE_NOT_FOUND', 要求堆栈:[] }

我希望能够做到。将文件移动到 src 文件夹并从那里运行文件

解决方法

该错误表示节点移动后无法再找到该模块

我认为您正在代码中的某处导入这些文件,

您需要找到这个并将其更改为新目录,

这将是类似的东西:

require("/prueba.js");

如果你将它移动到 Src 文件夹,那么也将它添加到路径中

require("/src/prueba.js");