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

fdir is not a constructor #37

Closed
itesainnovation opened this issue Jul 24, 2020 · 9 comments
Closed

fdir is not a constructor #37

itesainnovation opened this issue Jul 24, 2020 · 9 comments

Comments

@itesainnovation
Copy link

Hi there!

I'm getting this error while trying to create a new builder. Any ideas what's going on?

Thanks

@thecodrr
Copy link
Owner

Can you please show your code?

@martinvanwieringen
Copy link

martinvanwieringen commented Jul 26, 2020

I am getting the same error:

Your sample code:
const fdir = require("fdir").default;

// create the builder
const api = new fdir().withFullPaths().crawl("path/to/dir");

// get all files in a directory synchronously
const files = api.sync();

// or asynchronously
api.withPromise().then((files) => {
// do something with the result here.
console.log(files);
});

Result is:

const api = new fdir().withFullPaths().crawl("path/to/dir");
^

TypeError: fdir is not a constructor
at Object. (filesystem_crawler.js:5:13)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11

@thecodrr
Copy link
Owner

@martinvanwieringen

I think there was no need for require("fdir").default. Try with: const fdir = require("fdir").

@itesainnovation
Copy link
Author

@martinvanwieringen

I think there was no need for require("fdir").default. Try with: const fdir = require("fdir").

Exactly, it's fixed by not requiring default

@chalkygames123
Copy link

The type definition also seems to have the inconsistency.

スクリーンショット 2020-07-27 15 42 34

スクリーンショット 2020-07-27 15 43 11

@thecodrr
Copy link
Owner

@chalkygames123 fixing it right away

@thecodrr thecodrr reopened this Jul 27, 2020
@pl4yradam
Copy link

pl4yradam commented Jul 27, 2020

Error:

TypeError: fdir_1.default is not a constructor

Use:

import fdir from 'fdir';

const crawler: any = new fdir()
            .withBasePath()
            .filter((fPath) => fPath.endsWith('.exe'));

 const exes = [...crawler.crawl(folders[i].location).sync()];

Same issue

thecodrr added a commit that referenced this issue Jul 27, 2020
@thecodrr
Copy link
Owner

Apparently, export default doesn't work nicely with require so I had to migrate to using named imports. I have updated the documentation and README accordingly, please refer to that.

@chalkygames123
Copy link

Great, thanks!

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