我是nodejs的新手。尝试一个简单的导出(使用module.export)和导入(使用require() ),但是当我试图打印出导入的常量时,我得到的结果是“未定义”。请帮帮忙。下面提供的代码。此外,我意识到有导出/导入请求的方法,但我仍然希望通过使用module.export和ES6 ()来修复这个特定的错误。在intelliJ IDEA和VScode上也有同样的错误。
constants.js
const fname = 'Abdulraqib';
const lname = 'Olayanju';
module.export = {
fname : fname
};index.js
const name = require('./constant');
console.log(name.fname);package.json
{
"name": "fe-workshop",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}发布于 2020-04-12 09:15:13
它是module.exports而不是module.export
const fname = 'Abdulraqib';
const lname = 'Olayanju';
module.exports = {
fname : fname
};https://stackoverflow.com/questions/61165660
复制相似问题