Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误[错误模块未找到]:找不到模块_Javascript_Node.js - Fatal编程技术网

Javascript 错误[错误模块未找到]:找不到模块

Javascript 错误[错误模块未找到]:找不到模块,javascript,node.js,Javascript,Node.js,我正在做一个节点项目(截图)。我在helpers.js中有一个函数(URL),我在底部将其导出为: module.exports = { urls: urls, }; 在我的index.js中,我尝试使用以下方法导入它: import { urls } from '.helpers'; const myUrls = urls(1,3); 当我运行它时,我得到 Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/optionhomes

我正在做一个节点项目(截图)。我在helpers.js中有一个函数(URL),我在底部将其导出为:

module.exports = {
urls: urls,
};
在我的index.js中,我尝试使用以下方法导入它:

import { urls } from '.helpers';
const myUrls = urls(1,3);
当我运行它时,我得到

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/optionhomes11/nodeprojects/hayes/helpers' imported from /home/optionhomes11/nodeprojects/hayes/index.js Did you mean to import ../helpers.js?

我做错了什么?

您应该从
'./helpers'
导入,而不是从
'导入。helpers'

我还建议您安装
路径Intellisense
VS代码扩展。在处理嵌套路径时,它将非常有用。

您已经使用过

"type":"module"
然后确保您有
导入
文件必须是
.js
扩展名

使用.js扩展名

import urls from './helpers.js';
添加到package.json到

"type": "module",

我强烈建议不要混用模块系统。贾里德,我对node很陌生。我正在混合哪些模块系统?您正在混合节点的CJS模块系统(require/module.exports)和ES6模块(import/export)。除非您非常确定自己知道自己在做什么,否则不要这样做,因为存在一些微妙和粗俗的问题。谢谢,我将阅读这些。谢谢,对不起,输入错误,我是从“./helpers”导入的