1、Node版本 >= 13

2、使用 ES6 模块

a.js

export const A = 'A';

index.js

import { A } from './a.js';

console.log(A);

3、创建 package.json

{
    "type": "module"
}

4、直接运行即可

$ node index.js

 

其他方法参考 https://nodejs.org/api/esm.html

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2021-07-01
  • 2022-12-23
  • 2021-06-17
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
相关资源
相似解决方案