Appearance
介绍一些ESM & CommonJS模块相关的文章:
All you need to know to move from CommonJS to ECMAScript Modules (ESM) in Node.js 介绍如何从CommonJS迁移到ESM
语法的区别:
require() & module.exports
vsimport & export
commonjs独有的
__dirname
&__filename
如何在esm中的模拟jsimport { fileURLToPath } from "url"; import { dirname } from "path"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); console.log(__dirname); console.log(__filename);
如何在esm中使用 commonjs 中独有的
require()
方法jsimport { createRequire } from "module"; const require = createRequire(import.meta.url);
esm独有的顶层
await