-4

Here is the error I'm getting. Please help.

C:\Users\Val\Desktop\merncamp\server\middleware\index.js:1 import expressJwt from "express-jwt";

SyntaxError: The requested module 'file:///C:/Users/Val/Desktop/merncamp/server/node_modules/express-jwt/dist/index.js'
does not provide an export named 'default'
  at Object. (C:\Users\Val\Desktop\merncamp\server\middleware\index.js:1)
  at Generator.next ()
  at Object. (C:\Users\Val\Desktop\merncamp\server\routes\auth.js:1)
  at Generator.next ()
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

greybeard
  • 2,249
  • 8
  • 30
  • 66
  • Google might help: Import Error Does not provide export named default – Roko C. Buljan May 12 '22 at 08:39
  • Welcome to SO. Please write a title that describes the problem. The first part of your title is totally redundant, as almost everyone who asks a question is seeking for help and the second part seems to describe the broader task but not the specific problem. Please also read [ask] – jps May 12 '22 at 08:47

2 Answers2

1

I don't know the exact context of what you are trying to do, I will however take a shot in the dark.

The error you are seeing implies that you are asking for something that doesn't exist, based on the way you are trying to import express-jwt.

When code modules in javascript are created they can have named exports and a default export.

From your error it looks like you are importing using the following statement

import expressJWT from 'express-jwt'

This is asking for the 'default' export from that module. Looking at the NPM page for the package it looks like expressJWT is a named export. If this is the case, you would need to modify your import statement to the following

import { expressJWT } from 'express-jwt'

I hope this helps. For next time, try adding your code that is causing the error to help others to answer.

Glenn Holland
  • 580
  • 3
  • 19
0

//var { expressjwt: jwt } = require("express-jwt");
import { expressjwt } from "express-jwt";
const requireSignin =expressjwt({
  secret: process.env.JWT_SECRET,
  algorithms: ["HS256"],
});

export default requireSignin;

or

var { expressjwt: jwt } = require("express-jwt");

const requireSignin =jwt({
  secret: process.env.JWT_SECRET,
  algorithms: ["HS256"],
});

export default requireSignin;