Open Bidek56 opened 6 years ago
@Bidek56 No - does it really matter if this library is using ES5 or ES6? We have more compatibility with older versions of node + no build process right now. Why would we change that?
I think it does, b/c currently I can NOT do import without babel.
import reqdir from 'require-dir';
You can not
do imports in node without babel. That is completely separate from this project.
Then, what is "node --experimental-modules" for?
Not es6! https://nodejs.org/api/esm.html
It says: "Node.js contains support for ES Modules based upon the Node.js EP for ES Modules."
@Bidek56 import reqdir from 'require-dir';
will work just fine, use babel-register in your node project for ES6 imports. A library does not need to "be ES6" to work with imports.
node --experimental-modules
is experimental, doesn't work right, etc. we (and the rest of the community) aren't going to jump through hoops to support something nobody uses - just use babel.
Brandons-MacBook-Pro-2:api brandonros$ node --experimental-modules index.mjs
(node:10262) ExperimentalWarning: The ESM module loader is experimental.
/Users/brandonros/Desktop/foo/api/node_modules/require-dir/index.js:11
var parentFile = parent.filename;
^
TypeError: Cannot read property 'filename' of undefined
at Object.<anonymous> (/Users/brandonros/Desktop/foo/api/node_modules/require-dir/index.js:11:25)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:116:15)
at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
at async Loader.import (internal/modules/esm/loader.js:132:24)
import requireDir from 'require-dir'
const routes = requireDir('../routes')
$ node -v
v12.13.0
node --experimental-modules index.mjs
module.parent is undefined when trying to use with ECMAScript modules
@brandonros See above comment - it is labeled experimental, I will update the package when it is finalized and marked as stable.
Any updates on this? did someone find the replacement for this module, that works with ES6?
thank you
I'll reopen this, since it's been 3 years and this is no longer an experimental node feature. Likely to support modules requireDir will need to become an async function, so top-level await was needed.
Are you planning to upgrade this library to ES6? Is there a similar version of this library written in ES6? Thanks