module.exports = () => {
console.log('Learning NodeJs.');
};
index.mjs
import sampleModule from './sampleModule.mjs';
sampleModule();
Execution Error:
% node --experimental-modules index.mjs
file:///Users/c2ctechtv/Desktop/node-examples/index.mjs:1
import sampleModule from './sampleModule.mjs';
^^^^^^^^^^^^
SyntaxError: The requested module './sampleModule.mjs' does not provide an export named 'default'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:122:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:188:5)
at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
at async loadESM (node:internal/process/esm_loader:40:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)

Fix:
This error occurs when you try to import a default export from an ES module, but the module does not contain a default export named 'default'.
We make the following changes to our files to fix this error,
SampleModule.mjsexport const message = 'Learning NodeJs.';
index.mjs
import { message } from './sampleModule.mjs';
console.log(message);
Execution:
% node --experimental-modules index.mjs
Learning NodeJs.
-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to JavaScript,
- Get Current time in GMT/UTC using JavaScript
- How to get current URL Location using Javascript HTML
- Excel Fix: SECURITY RISK Microsoft has blocked macros from running because the source of this file is untrusted.
- Convert Javascript object to JSON String example
- Fix: ReferenceError: require is not defined in ES module scope [Node]
- [JavaScript] Remove all Newlines From String
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- Fix: Error: error:0308010C:digital envelope routines::unsupported NodeJs/Vue/React
- Pure JavaScript Digital Clock Widget to get GMT/UTC Time Now
- Fix: npm vs code eacces permission denied unlink /usr/local/bin/code
- Power of Print Statements in JavaScript: A Comprehensive Guide
- [javaScript] Convert text case to lowercase
- JavaScript: Count Words in a String
- JavaScript date in yyyy-MM-dd format
- How to send email from JavaScript HTML using mailto
- How to get UTC (GMT) time using JavaScript
- JavaScript: Generate Random Numbers between 1 and 3
- How to get query string in JavaScript HTML location.search
- Fix: Uncaught ReferenceError: exit is not defined - Node.js REPL
- Detect if Cookies are enabled using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- Send Extra Data with Ajax Get or Post Request
- Loading previous page using html button using JavaScript
- 10 ways to Convert String to a Number in JavaScript
- JavaScript: Check if variable is a number
More Posts:
- Word wrap text in Notepad++ - NotepadPlusPlus
- Get the Complete Sha256 Container ID for Docker Run Command - Docker
- How to download Google Chrome Enterprise MSI Installer File - Chrome
- Remove Trailing zeros BigDecimal Java - Java
- How to add a Delay of a Few Seconds in Java Program - Java
- Base64 Encoding Decoding in Python Programming - Python
- Android Emulator 5.1.1 not loading on Mac OS X Android Studio - Android-Studio
- Java: Pass Predicate as Parameter to a Method Example - Java