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

Incorrectly reporting hasModule = true #71

Closed
montogeek opened this issue Jul 11, 2015 · 5 comments
Closed

Incorrectly reporting hasModule = true #71

montogeek opened this issue Jul 11, 2015 · 5 comments

Comments

@montogeek
Copy link
Contributor

Hi!

I am using numbro in the browser, like this:

var numbro = require('numbro');

But when compiling the source file I get this error on Chrome:

Uncaught TypeError: x.readdirSync is not a function

Basically the hasModule is returning true even when is not running in a NodeJS environment.

if (hasModule) {
        module.exports = numbro;

        // Load all languages
        var fs = require('fs'),
            path = require('path');
        var langFiles = fs.readdirSync(path.join(__dirname, 'languages'));
        langFiles.forEach(function (langFile) {
            numbro.language(path.basename(langFile, '.js'), require(path.join(__dirname, 'languages', langFile)));
        });
    }

Note:

I am using Browserify v10.2.4.
numbro 1.5.0

Thanks!

@montogeek
Copy link
Contributor Author

After downgrading it to 1.1.1, the initial version that I installed the problem was gone.
Investigating I found that this commit introduced that code foretagsplatsen@8ca2bec

@BenjaminVanRyseghem
Copy link
Owner

Thanks

We have to fix the hasModule as now it's more isRunningInNode

😄

@montogeek
Copy link
Contributor Author

What if we make language files as modules?

var numbro = require('numbro');
var numbro_es = require('numbro_es');

@BenjaminVanRyseghem
Copy link
Owner

I think it's already the case.
But it can be a bit boring to load all the languages this way

@BenjaminVanRyseghem
Copy link
Owner

can you check that #101 fixes this issue?

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

2 participants