我正在尝试在 d3js 和 Angular 的帮助下构建一个地铁图。我正在使用 Angular 8 和 d3 版本 3.4.13。在执行 npm start 时,我遇到了一系列错误。任何弄清楚为什么会发生这种情况的线索都会有很大帮助。
这是存储库的链接: https://github.com/reshnaz/Tubemap.git
我收到以下错误:
ERROR in ./node_modules/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'child_process' in '/home/reshma/Documents/Angular/tubemap_project/tubemap-dashboard/node_modules/xmlhttprequest/lib'ERROR in ./node_modules/jsdom/lib/jsdom/browser/index.js
Module not found: Error: Can't resolve 'cssstyle' in '/home/reshma/Documents/Angular/tubemap_project/tubemap-dashboard/node_modules/jsdom/lib/jsdom/browser'ERROR in ./node_modules/jsdom/lib/jsdom/level2/style.js
Module not found: Error: Can't resolve 'cssstyle' in '/home/reshma/Documents/Angular/tubemap_project/tubemap-dashboard/node_modules/jsdom/lib/jsdom/level2'ERROR in ./node_modules/jsdom/lib/jsdom.js
Module not found: Error: Can't resolve 'fs' in '/home/reshma/Documents/Angular/tubemap_project/tubemap-dashboard/node_modules/jsdom/lib'ERROR in ./node_modules/jsdom/lib/jsdom/level2/html.js
Module not found: Error: Can't resolve 'fs' in '/home/reshma/Documents/Angular/tubemap_project/tubemap-dashboard/node_modules/jsdom/lib/jsdom/level2'ERROR in ./node_modules/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'fs' in '/home/reshma/Documents/Angular/tubemap_project/tubemap-dashboard/node_modules/xmlhttprequest/lib'ERROR in ./node_modules/jsdom/lib/jsdom.js
Module not found: Error: Can't resolve 'request' in '/home/reshma/Documents/Angular/tubemap_project/tubemap-dashboard/node_modules/jsdom/lib'
最佳答案
我无法相信该问题是由您使用的旧版本 d3 以外的任何其他原因引起的。
您看到的有关缺少模块的错误可能是因为您运行了npm install
,这生成了一系列错误,您要么没有注意到,要么故意忽略了这些错误,并尝试继续进行,如下所示:如果没有什么问题的话。或者也许 npm install
运行良好,但您的 node_modules
文件夹包含 React.js 项目留下的大量垃圾?如果删除 node_modules
文件夹并尝试再次运行 npm install
会发生什么?
你提到的原始 React.js 应用程序是如何工作的我不能说,特别是因为你没有提供你提到的 GitHub 源代码的链接。也许它使用了较旧版本的 React,而这又需要其他较旧的依赖项。决定使用最新版本的 Angular 与决定在同一项目中使用如此旧版本的 d3 有点不一致。
我唯一的建议(如果还不是很明显的话)就是硬着头皮将你的项目升级到最新版本的 d3。是的,您必须更改代码调用 d3 的方式,因为 d3 在版本 3 和版本 5 之间发生了一些变化。但这太糟糕了。
关于javascript - d3js/Angular 8 应用程序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58563237/