'import error when trying to import express-jwt

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)



Solution 1:[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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Glenn Holland