node.js - 使用 dc 和 Node.js 预渲染图表

标签 node.js d3.js npm dc.js crossfilter

我正在尝试使用 npm 通过 dc.js 预渲染图表

但是当我在代码中包含 dc 时,它会抛出错误,我是 node.js 中的 nwebie,尝试搜索答案没有运气,可能应该是版本错误我了解到 jsdom 版本 > 1 没有 createWindow( );方法,但更改版本并调用 npm install 和 update 也不起作用。任何帮助都非常感谢,提前感谢

我的package.json

{
  "name": "binode",
  "version": "1.0.0",
  "description": "binode testing",
  "main": "index.js",
  "scripts": {
    "start": "node index"
  },
  "author": "abc",
  "license": "MIT",
  "dependencies": {
    "body-parser": "^1.13.3",
    "d3": "^3.5.6",
    "dc": "^1.7.3",
    "express": "^4.13.3",
    "jsdom": "^1.5.0"
  }
}

错误:

/learn/nodeSample/biNode/node_modules/dc/globals.js:2
    window = global.window = document.createWindow();
                                      ^
TypeError: undefined is not a function
    at Object.<anonymous> (/Volumes/Official/learn/nodeSample/biNode/node_modules/dc/globals.js:2:39)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Volumes/Official/learn/nodeSample/biNode/node_modules/dc/index.js:8:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

npm ERR! Darwin 14.5.0
npm ERR! argv "node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.7
npm ERR! npm  v2.14.1
npm ERR! code ELIFECYCLE
npm ERR! binode@1.0.0 start: `node index`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the binode@1.0.0 start script 'node index'.
npm ERR! This is most likely a problem with the binode package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index
npm ERR! You can get their info via:
npm ERR!     npm owner ls binode
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Volumes/Official/learn/nodeSample/biNode/npm-debug.log

npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'start' ]
2 info using npm@2.14.1
3 info using node@v0.12.7
4 verbose node symlink /usr/local/bin/node
5 verbose run-script [ 'prestart', 'start', 'poststart' ]
6 info prestart binode@1.0.0
7 info start binode@1.0.0
8 verbose unsafe-perm in lifecycle true
9 info binode@1.0.0 Failed to exec start script
10 verbose stack Error: binode@1.0.0 start: `node index`
10 verbose stack Exit status 1
10 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:214:16)
10 verbose stack     at EventEmitter.emit (events.js:110:17)
10 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
10 verbose stack     at ChildProcess.emit (events.js:110:17)
10 verbose stack     at maybeClose (child_process.js:1015:16)
10 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
11 verbose pkgid binode@1.0.0
12 verbose cwd /Volumes/Official/learn/nodeSample/biNode
13 error Darwin 14.5.0
14 error argv "node" "/usr/local/bin/npm" "start"
15 error node v0.12.7
16 error npm  v2.14.1
17 error code ELIFECYCLE
18 error binode@1.0.0 start: `node index`
18 error Exit status 1
19 error Failed at the binode@1.0.0 start script 'node index'.
19 error This is most likely a problem with the binode package,
19 error not with npm itself.
19 error Tell the author that this fails on your system:
19 error     node index
19 error You can get their info via:
19 error     npm owner ls binode
19 error There is likely additional logging output above.
20 verbose exit [ 1, true ]

我的简单js文件:

var express = require('express');
var app = express();
var d3 = require('d3');
var dc = require('dc');
var crossfilter = require('crossfiler');
var jsdom = require('jsdom');
global.d3 = d3;
var port = 2000;
app.listen(port,function(){
console.log("app listing port "+port)
});

我刚刚开始,它本身就抛出了错误

最佳答案

我尝试在node_modules/dc内运行npm install 然后又出现了一个问题index.js no dc is Defineed 添加 将 require('./dc') 更改为 dc =require('./dc') 现在它正在工作..

关于node.js - 使用 dc 和 Node.js 预渲染图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32311092/

相关文章:

node.js - 直接运行时防止 `npm publish`

node.js - 无法通过 npm 安装 Ionic

javascript - 设置文本宽度或将文本放入 div 中

javascript - 对 d3 的 selectAll 方法的好奇心

Angular Material 设计未显示

node.js - 使用 PM2 运行 Gatsby JS

node.js - 如何在没有整个模块的情况下将类型导入 Typescript?

node.js - npm 安装失败并出现错误

node.js - 如何在 Hogan js 中使用带有 for 循环的 if 语句

javascript - D3 : Using force layout for word clouds