Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 version #58

Open
Bidek56 opened this issue Oct 16, 2018 · 11 comments
Open

ES6 version #58

Bidek56 opened this issue Oct 16, 2018 · 11 comments

Comments

@Bidek56
Copy link

Bidek56 commented Oct 16, 2018

Are you planning to upgrade this library to ES6? Is there a similar version of this library written in ES6? Thanks

@yocontra
Copy link
Collaborator

@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?

@Bidek56
Copy link
Author

Bidek56 commented Oct 16, 2018

I think it does, b/c currently I can NOT do import without babel.

import reqdir from 'require-dir';

@stephenlacy
Copy link
Collaborator

You can not do imports in node without babel. That is completely separate from this project.

@Bidek56
Copy link
Author

Bidek56 commented Oct 16, 2018

Then, what is "node --experimental-modules" for?

@stephenlacy
Copy link
Collaborator

Not es6! https://nodejs.org/api/esm.html

@Bidek56
Copy link
Author

Bidek56 commented Oct 16, 2018

It says: "Node.js contains support for ES Modules based upon the Node.js EP for ES Modules."

@yocontra
Copy link
Collaborator

yocontra commented Oct 16, 2018

@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.

@brandonros
Copy link

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 

image

module.parent is undefined when trying to use with ECMAScript modules

@yocontra
Copy link
Collaborator

@brandonros See above comment - it is labeled experimental, I will update the package when it is finalized and marked as stable.

@Kostanos
Copy link

Any updates on this? did someone find the replacement for this module, that works with ES6?

thank you

@yocontra
Copy link
Collaborator

yocontra commented May 11, 2022

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.

@yocontra yocontra reopened this May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants