Going round in circles here, I'm using a module called get-folder-size https://www.npmjs.com/package/get-folder-size
This only works, it seems, inside an ES6 module. So I've found out how to do this, and created one. Now I need to import that into my commonjs app (node v14
).
const mymod = require('mymod.js')
now won't work because I can't require it
import mymod from 'mymod.js'
won't work. Cannot use import outside a module
change to mymod.mjs
doesn't help
add {"type": "module"}
to package.json
at my Node app's entry point as suggested by google, and now it's erroring about loads of stuff that it doesn't like.
So I started off with
index.js
const mymod = require('./mymod.js');
mymod.js
const getFolderSize = (await import('get-folder-size')).default;
const mymod = async (org) => {
let size = await getFolderSize.loose('./');
return size;
};
module.exports = { mymod };
and I've ended up (a dozen iterations later), with a still not working:
index.js
import mymod from './mymod.mjs';
mymod.mjs
import getFolderSize from 'get-folder-size';
const mymod = async (org) => {
let size = await getFolderSize.loose('./');
return size;
};
export default mymod;
I think that explains it at least.. it's late, and I don't really get what's going on - this used to all work so beautifully! Worse, everything that I can find to try and help solve this seems to be related to packaging front end apps :/