Coder Social home page Coder Social logo

Comments (6)

BenjaminVanRyseghem avatar BenjaminVanRyseghem commented on July 30, 2024

but this code is in a if statement (checking that there is a global variable module)

Isn't that good enough?

from numbro.

 avatar commented on July 30, 2024

No, browserify is CommonJS and have module.exports but no have native 'fs' and '' 'path' in the code validate if a CommonJS but no if have fs or path modules.

possible solution

// CommonJS module is defined
    if (hasModule) {
        module.exports = numbro;

        // Load all languages if have modules (NodeJs or io.js)
        var fs = require('fs'),
            path = require('path');

        if(fs && 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)));
             });
        }
    }

from numbro.

jfeltesse avatar jfeltesse commented on July 30, 2024

Trying to use it with webpack/ES6 (with babel)/npm and it yielded warnings/errors that sound related to this issue.

Note that simply importing spit tons of warnings & errors while importing the dist file directly still failed but with much less stuff in the console.
FYI I'm using momentjs and by simply importing it everything works like a charm. Mentioning this because the README states the lib has been influenced by it.

"Simple" import

// es6 file
import numbro from "numbro";

// console output
WARNING in ./~/numbro/numbro.js
Critical dependencies:
970:60-112 the request of a dependency is an expression
 @ ./~/numbro/numbro.js 970:60-112

WARNING in ./~/numbro/CHANGELOG-Numeraljs.md
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/CHANGELOG-Numeraljs.md Line 1: Unexpected identifier
You may need an appropriate loader to handle this file type.
| _This is the historical changelog for the [`numeral-js`
| project](https://github.com/adamwdraper/Numeral-js), which `numbro` is built upon. The `numbro`
| changelog is at [CHANGELOG.md](CHANGELOG.md)._
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/CHANGELOG.md
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/CHANGELOG.md Line 1: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
| ### 1.5.0
|
| - Adds support for Hebrew (he-LI). Thanks to @eli-zehavi
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/LICENSE
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/LICENSE Line 1: Unexpected number
You may need an appropriate loader to handle this file type.
| Copyright (c) 2015 Företagsplatsen
|
| Permission is hereby granted, free of charge, to any person
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/LICENSE-Numeraljs
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/LICENSE-Numeraljs Line 1: Unexpected number
You may need an appropriate loader to handle this file type.
| Copyright (c) 2014 Adam Draper
|
| Permission is hereby granted, free of charge, to any person
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/README.md
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/README.md Line 1: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
| # [numbro](https://numbrojs.com/)
|
| A javascript library for formatting and manipulating numbers.
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/bower.json
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/bower.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "name": "numbro",
|   "repo": "foretagsplatsen/numbro",
|   "version": "1.5.0",
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/component.json
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/component.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "name": "numbro",
|   "repo": "foretagsplatsen/numbro",
|   "version": "1.5.0",
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/package.json
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "name": "numbro",
|   "version": "1.5.0",
|   "description": "Format and manipulate numbers.",
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/resources/LICENSE
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/resources/LICENSE Line 1: Unexpected number
You may need an appropriate loader to handle this file type.
| Copyright 2015 Benjamin Van Ryseghem
|
| Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible.
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/resources/README.md
Module parse failed: /Users/julien/dev/repos/app/client/node_modules/numbro/resources/README.md Line 1: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
| # Ranko the Raccoon
|
| Ranko is the mascott of the [numbro](https://github.com/foretagsplatsen/numbro) project.
 @ ./~/numbro ^\.\/.*$

WARNING in ./~/numbro/dist/numbro.js
Critical dependencies:
970:60-112 the request of a dependency is an expression
 @ ./~/numbro/dist/numbro.js 970:60-112

WARNING in ./~/numbro/dist/numbro.min.js
Critical dependencies:
8:9915-9955 the request of a dependency is an expression
 @ ./~/numbro/dist/numbro.min.js 8:9915-9955

ERROR in ./~/numbro/numbro.js
Module not found: Error: Cannot resolve module 'fs' in /Users/julien/dev/repos/app/client/node_modules/numbro
 @ ./~/numbro/numbro.js 966:17-30

ERROR in ./~/numbro/Gruntfile.js
Module not found: Error: Cannot resolve module 'fs' in /Users/julien/dev/repos/app/client/node_modules/numbro
 @ ./~/numbro/Gruntfile.js 1:9-22

ERROR in ./~/numbro/dist/numbro.js
Module not found: Error: Cannot resolve module 'fs' in /Users/julien/dev/repos/app/client/node_modules/numbro/dist
 @ ./~/numbro/dist/numbro.js 966:17-30

ERROR in ./~/numbro/dist/numbro.min.js
Module not found: Error: Cannot resolve module 'fs' in /Users/julien/dev/repos/app/client/node_modules/numbro/dist
 @ ./~/numbro/dist/numbro.min.js 8:9783-9796

ERROR in ./~/numbro/tests/languages/locale-codes.js
Module not found: Error: Cannot resolve module 'require-dir' in /Users/julien/dev/repos/app/client/node_modules/numbro/tests/languages
 @ ./~/numbro/tests/languages/locale-codes.js 3:17-39

"Direct" import

// es6 file
import numbro from "../node_modules/numbro/dist/numbro";

// console output
WARNING in ./~/numbro/dist/numbro.js
Critical dependencies:
970:60-112 the request of a dependency is an expression
 @ ./~/numbro/dist/numbro.js 970:60-112

WARNING in ./~/numbro/dist/numbro.min.js
Critical dependencies:
8:9915-9955 the request of a dependency is an expression
 @ ./~/numbro/dist/numbro.min.js 8:9915-9955

ERROR in ./~/numbro/dist/numbro.js
Module not found: Error: Cannot resolve module 'fs' in /Users/julien/dev/repos/app/client/node_modules/numbro/dist
 @ ./~/numbro/dist/numbro.js 966:17-30

ERROR in ./~/numbro/dist/numbro.min.js
Module not found: Error: Cannot resolve module 'fs' in /Users/julien/dev/repos/app/client/node_modules/numbro/dist
 @ ./~/numbro/dist/numbro.min.js 8:9783-9796

from numbro.

clayzermk1 avatar clayzermk1 commented on July 30, 2024

👍 also seeing this on numbro 1.5.0 and browserify 11.0.1.

Copying moment's module definition pattern or implementing UMD would be a couple ways to go about this.

I'll try a couple things and see what I come up with.

from numbro.

jenswegar avatar jenswegar commented on July 30, 2024

1.5.1 seems to have this issue as well when using browserify. The error I get in the browser is

TypeError: fs.readdirSync is not a function

which occurs in this block of code:

// CommonJS module is defined
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)));
    });
}

1.1.1 did not have this problem and since it's enough for my needs right now, I'm sticking to that version for the time being.

from numbro.

BenjaminVanRyseghem avatar BenjaminVanRyseghem commented on July 30, 2024

can you check that #101 fixes this issue?

from numbro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.