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

Time:05-16

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.

CodePudding user response:

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

CodePudding user response:

Try to use below command

npm i @types/node

  • Related