Search code examples
node.jsenvironment-variablesdotenv

Node modules are not exporting


my node modules are not importing. I tried in export default and export const and each and every way. every each times I get either reference error or a syntax error.

I get reference error when i update my code like below.(ReferenceError: require is not defined)

const viewEngine = require( './config/viewEngine');

I get syntax error when i update my code like below.(SyntaxError: The requested module './config/viewEngine' does not provide an export named 'default')

import viewEngine from './config/viewEngine';

I get syntax error when i update my code like below.(SyntaxError: The requested module './config/viewEngine' does not provide an export named 'viewEngine')

import {viewEngine} from './config/viewEngine';

and the ways i tried to export:

  1. module.exports = configViewEngine;
  2. module.exports = {configViewEngine};

and my dotenv is not getting defined. I tried every each ways to import dotenv too.

here is my package.json.

{
  "name": "chatbot",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --experimental-modules --es-module-specifier-resolution=node src/server.js"
  },
  "type": "module",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.14.3",
    "@babel/node": "^7.14.2",
    "@babel/preset-env": "^7.14.2",
    "body-parser": "^1.19.0",
    "browserify": "^17.0.0",
    "dotenv": "^10.0.0",
    "ejs": "^3.1.6",
    "express": "^4.17.1",
    "localtunnel": "^2.0.1",
    "nodemon": "^2.0.7",
    "npm-upgrade": "^3.0.0"
  }
}

I use windows 10.

please help thanks!


Solution

  • After upgrading npm version it worked.