0

Lets say you are using Module instead of CommonJS in your npm project. How do you implement all of the functions of module. like module.exports or module.parent inside of your Module. Are there replacements for it? To implement "require" into a Module type project you would do:

import {createRequire} from "module"
const require = createRequire(import.meta.url);

But how would you implement module? With something like this?:

import {Module} from "module"
const module = Module(import.meta.url);
DcraftBg
  • 27
  • 5
  • You simply don't. `exports` are working different in ES modules, and `.parent` was a bad idea even with CommonJS. – Bergi May 01 '22 at 12:26
  • @Bergi Yea it took me a few hours but i did find out an easier aproach with cwd(). I also made my 1st actual library for npm called file-rel-path which basically gets the relative path of one file to another. I am here to ask you something tho, how do i use __dirname in module npm scripts? – DcraftBg May 01 '22 at 13:25
  • https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules – Bergi May 01 '22 at 13:31

0 Answers0