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

TypeError: table is not a function #14

Closed
vvebvvizard opened this issue Jul 12, 2016 · 7 comments
Closed

TypeError: table is not a function #14

vvebvvizard opened this issue Jul 12, 2016 · 7 comments

Comments

@vvebvvizard
Copy link

vvebvvizard commented Jul 12, 2016

Hi,

I tried to use table with Gulp in our starter kit. I had to use require() to import it because I can't install babel

But when I try to use table with your exemple, it return me this error.

data = [
    ['0A', '0B', '0C'],
    ['1A', '1B', '1C'],
    ['2A', '2B', '2C']
];

options = {
    column: {
        0: {
            alignment: 'left',
            minWidth: 10
        },
        1: {
            alignment: 'center',
            minWidth: 10
        },
        2: {
            alignment: 'right',
            minWidth: 10
        }
    }
};

output = table(data, options);

Is there a way to use table without ES6?

Thanks for your help!

@vvebvvizard
Copy link
Author

It seems to work with this path in the require var table = require("table/dist/table");

@Nepoxx
Copy link

Nepoxx commented Nov 22, 2016

...but why?

@gajus
Copy link
Owner

gajus commented Nov 22, 2016

...but why?

You should't have the issue describe above in the current version.

Have you pulled the latest npm package?

What error are you getting when importing table?

@Nepoxx
Copy link

Nepoxx commented Nov 22, 2016

⋊> ~/d/tableTest npm i table --save                                                                                                                                                                                                   09:32:38
tabletest@1.0.0 /home/nepoxx/dump/tableTest
`-- table@3.8.3 
  +-- ajv@4.9.0 
  | +-- co@4.6.0 
  | `-- json-stable-stringify@1.0.1 
  |   `-- jsonify@0.0.0 
  +-- ajv-keywords@1.1.1 
  +-- chalk@1.1.3 
  | +-- ansi-styles@2.2.1 
  | +-- escape-string-regexp@1.0.5 
  | +-- has-ansi@2.0.0 
  | | `-- ansi-regex@2.0.0 
  | +-- strip-ansi@3.0.1 
  | `-- supports-color@2.0.0 
  +-- lodash@4.17.2 
  +-- slice-ansi@0.0.4 
  `-- string-width@2.0.0 
    `-- is-fullwidth-code-point@2.0.0 

npm WARN tabletest@1.0.0 No description
npm WARN tabletest@1.0.0 No repository field.
⋊> ~/d/tableTest echo "var table = require('table'); table(['a','b','c'])" > app.js                                                                                                                                                   09:32:44
⋊> ~/d/tableTest node app.js                                                                                                                                                                                                          09:33:17
/home/nepoxx/dump/tableTest/app.js:1
(function (exports, require, module, __filename, __dirname) { var table = require('table'); table(['a','b','c'])
                                                                                            ^

TypeError: table is not a function
    at Object.<anonymous> (/home/nepoxx/dump/tableTest/app.js:1:93)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:142:18)
    at node.js:939:3

Using var table = require("table/dist/table"); works as expected, however.

I'm using node v5.9.0.

@gajus
Copy link
Owner

gajus commented Nov 22, 2016

@Nepoxx fixed v4.0.1 that fixes this issue. See https://github.com/gajus/table/tree/v4.0.1#usage

Use:

const {table} = require('table');

@Nepoxx
Copy link

Nepoxx commented Nov 22, 2016

Thanks! (I use const table = require('table').table since object destructuring is a harmony feature and it is not enabled in node by default)

Forgive my ignorance, but where would import {table} from 'table'; be valid?

@gajus
Copy link
Owner

gajus commented Nov 22, 2016

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

3 participants