Created
May 24, 2018 23:49
-
-
Save Krabaton/668a8de2d104624d14f53c960e26f2b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There have been proposals about exposing these variables through import.meta, but for now, you need a hacky workaround that I found here: | |
// expose.js | |
module.exports = {__dirname}; | |
// use.mjs | |
import expose from './expose.js'; | |
const {__dirname} = expose; | |
In Node.js 10 there's an alternative that doesn't require creating multiple files: | |
import path from 'path'; | |
const __dirname = path.dirname(new URL(import.meta.url).pathname); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment