'Why i can't import "os" modules with "import" syntax?

With my node(v16.13.2)

const os = require("os");

this is perfectly work.

But

import os from "os";

This gives me an error that Module 'os' has no default export

I don't understand why it is.

And why node is designed like that.



Solution 1:[1]

you can fix this by saving the file with .mjs extension instead of .js, or by adding { "type": "module" } to your package.json file

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 Mohamed Mirghani