简体   繁体   English

如何将 dc.js 与 next.js(星号/通配符导入问题)一起使用?

[英]How to use dc.js with next.js (asterisk/wildcard import issue)?

Within a next.js (12.3.1) application I have a chart component where I import and use dc.js (7.6.1):在 next.js (12.3.1) 应用程序中,我有一个图表组件,我在其中导入并使用 dc.js (7.6.1):

import * as dc from 'dc'

The chart is correctly shown and using an asterisk/wildcard in the import statement seems to be the only way to do so.图表显示正确,在导入语句中使用星号/通配符似乎是唯一的方法。

However, importing dc that way seems to "destroy" the debugging feature of Google Chrome Dev tools.但是,以这种方式导入 dc 似乎“破坏”了 Google Chrome 开发工具的调试功能 The web application does not stop at breakpoints any more. web 应用程序不再在断点处停止。 And unfortunately, I do not get a warning from next.js, like "* imports are not supported" or "Debug mode stopped due to an import issue with 'dc'".不幸的是,我没有收到来自 next.js 的警告,例如“* 不支持导入”或“由于‘dc’的导入问题导致调试模式停止”。 If I remove the dc import, the debugging works again as expected.如果我删除 dc 导入,调试将按预期再次工作。

=> How to use dc.js with next.js without getting debugging issues in Google Chrome Dev Tools? => 如何在 next.js 中使用 dc.js 而不会在 Google Chrome 开发工具中出现调试问题?

Maybe nextjs does not support asterisk/wildcard imports?也许 nextjs 不支持星号/通配符导入? It took me a while to find out that the debugging issue is due to the dc import... First thought it would be an issue with Chrome Dev Tools, a source mapping issue or an issue with a configuration file.我花了一段时间才发现调试问题是由于 dc import 引起的...首先认为这将是 Chrome Dev Tools 的问题、源映射问题或配置文件的问题。

I moved the import from my chart component to the _app.js file of next.js. Then I pass dc down to the components as a property.我将导入从我的图表组件移动到 next.js 的 _app.js 文件。然后我将 dc 作为属性传递给组件。 That strategy somehow solves the debugging issue, don't know why exactly.该策略以某种方式解决了调试问题,不知道为什么。

import React from 'react';
import * as dc from 'dc';
import './stylesheet.css'
import 'dc/dist/style/dc.min.css';
import 'bootstrap/dist/css/bootstrap.min.css';

function MyApp({ Component, pageProps }) {
  //dc causes debugging issues when imported in chart components,
  //=> As A workaround, we import dc here and
  //pass it on to the chart components. 
  let params = {...pageProps};
  params['dc'] = dc;
  return <Component {...params} />
}

export default MyApp

=> Next.js seems to support * imports, but not on all levels of the application?! => Next.js 似乎支持*导入,但不是在所有级别的应用程序上?!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM