在同一目录中导入文件时发现“MODULE_NOT_FOUND”错误

问题描述 投票:0回答:1

enter image description here

enter image description here

无法从 users.js 文件导入 Users 数组

尝试使用 import 语句以及 with

进行导入
const Users = require('users')' // this is the code i have been using to import the file

两个文件,index.js 和 users.js 都在同一目录中

javascript node.js express
1个回答
0
投票

如果您不使用模块,则必须将导出类型更改为

module.exports= {Users}
export.Users = Users

index.js
文件中的用户导入为

const { Users } = require("./users.js");

检查 CodeSandbox 以解决您的问题此处

© www.soinside.com 2019 - 2024. All rights reserved.