最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Browserify DataTables - Stack Overflow

programmeradmin2浏览0评论

I tried following the instructions at NPM packages - DataTables but I still can't get it to bundle with Browserify.

Here is my minimal, plete, and verifiable example:

app.js

'use strict'

var $ = require('jquery')
var dt = require('datatables-dt')()

$(document.getElementById('table')).DataTable()

Output of npm list

[email protected] /home/RinkAttendant6/www/foo
├─┬ [email protected]
│ └── [email protected]
└── [email protected]

Output of browserify app.js -o bundle.js

Error: Cannot find module 'datatables-dt' from '/home/RinkAttendant6/www/foo'
    at /usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
    at process (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
    at ondir (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
    at load (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
    at onex (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
    at /usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.onplete (fs.js:82:15)

What am I doing wrong?

I tried following the instructions at NPM packages - DataTables but I still can't get it to bundle with Browserify.

Here is my minimal, plete, and verifiable example:

app.js

'use strict'

var $ = require('jquery')
var dt = require('datatables-dt')()

$(document.getElementById('table')).DataTable()

Output of npm list

[email protected] /home/RinkAttendant6/www/foo
├─┬ [email protected]
│ └── [email protected]
└── [email protected]

Output of browserify app.js -o bundle.js

Error: Cannot find module 'datatables-dt' from '/home/RinkAttendant6/www/foo'
    at /usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
    at process (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
    at ondir (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
    at load (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
    at onex (/usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
    at /usr/lib/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.onplete (fs.js:82:15)

What am I doing wrong?

Share Improve this question asked Nov 27, 2015 at 3:17 rink.attendant.6rink.attendant.6 46.5k64 gold badges110 silver badges157 bronze badges 3
  • Have you tried adding browserify-shim? – Raju Bera Commented Nov 27, 2015 at 3:24
  • @RajuBera No. Is there any reason I need browserify-shim for things that are CommonJS patible? – rink.attendant.6 Commented Nov 27, 2015 at 3:25
  • You are right, if it's monJs module we don't need of browserify-shim. – Raju Bera Commented Nov 27, 2015 at 3:35
Add a ment  | 

2 Answers 2

Reset to default 4

According to the package vendor, the datatables package should be used instead of datatables-dt unless Bootstrap or Foundation is used.

Refer to https://github./DataTables/DataTables/issues/434#issuement-161278064

Instead use:

var dt = require('datatables')()

The reason for this is that the datatables-dt package does not contain a Javascript file - it doesn't need one - it contains only CSS (it should actually contain a couple of images as well, that will be corrected in 1.10.11).

No Javascript file is required there since the DataTables defaults are suitable for DataTables styling. The same is not the case for Bootstrap, etc.

Using another remendation within that github issue thread worked for me.

See: https://github./DataTables/DataTables/issues/434#issuement-113286718

var DataTable = require('datatables')()

$.fn.DataTable = DataTable

That code worked with or without a browserify-shim entry for datatables.

发布评论

评论列表(0)

  1. 暂无评论