1 | initial version |
Yes, native ES modules in Node.js 16 can allow importing from the root directory using the import
statement. However, it requires configuring the package.json
file to specify the root directory as a module path. This can be done by setting the type
field in package.json
to "module"
and adding a "exports"
field that maps the root directory to the default
export of index.js
. Once configured, the root directory can be imported as a module using the following syntax:
import module from '/'
Note that importing from the root directory will only work with native ES modules, and not with CommonJS modules.