Madan Gopal
Madan Gopal

Reputation: 1

"errorMessage": "SyntaxError: Named export 'post' not found. The requested module 'axios' is a CommonJS module which maynot support all module.exports

Updated NodeJs version from 16.x to 20.x and changed commonjs module to ES Module but resulted in this error. Added Type Module in Package.json

const axios = require('axios'); -\> import axios from 'axios';

and

export async function InvokeRestService(url, data) {
    try {
        return  await axios.post(url, data);
    } catch (err) {
        handleError(url, err, 'InvokeRestService');
    }
 }

and tried

import axios,{ Post } from 'axios'; 

and

export async function InvokeRestService(url, data) {
    try {
        return  await post(url, data);
    } catch (err) {
        handleError(url, err, 'InvokeRestService');
    }
 }

but still throws ERROR:Uncaught Exception

SyntaxError: Named export 'post' not found. The requested module 'axios' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from 'axios';\nconst { post } = pkg;\n

Error Image

Upvotes: 0

Views: 222

Answers (0)

Related Questions