nodejs默认使用CommonJS,那么在引用包的时候使用以下方式引用包
var http = require("http");
但是,如果在package.json中定义
"type": "module",
就必须使用import方式引用包,否则会报错require is not defined in ES module scope, you can use import instead,因为使用module之后,使用的就是es6而不是commonJS。
使用require()
来导入CommonJS模块。如果您正在使用ES6,则应该使用import
来导入ES6模块