I'm getting into a case not covered in How to bulk convert some javascript code from import to require?.
Here is the original code from npm package hot-import
:
import * as assert from 'assert'
import * as fs from 'fs'
import * as path from 'path'
import hotImport from 'hot-import'
I converted them to,
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const hotImport = require('hot-import')
const hotMod = await hotImport(MODULE_FILE)
but got:
TypeError: hotImport is not a function
After some massive trial-and-errors, I found that const { hotImport } = require('hot-import')
works, but I have no idea why.
Can somebody summarize, when to use const hotImport = require('hot-import')
and when to use const { hotImport } = require('hot-import')
please?
And also related, why the demo code use,
import * as fs from 'fs'
instead of
import fs from 'fs'
? what's the differences between the two, and when to choose which?