简体   繁体   中英

using web-worker in react

// here is my web-worker code

 import * as d3 from 'd3'; // import d3 from 'https://d3js.org/d3-collection.v1.min.js'; // importScripts('d3'); //fibo.worker.js // eslint-disable-next-line import/no-anonymous-default-export export default () => { // eslint-disable-next-line no-restricted-globals self.onmessage = (message) => { const { nodes, links, width, height } = message.data; const simulation = d3.forceSimulation(nodes).force( 'link', d3.forceLink(links) // This force provides links between nodes.id((d) => d.id) // This sets the node id accessor to the specified function. If not specified, will default to the index of a node. .distance(10) ).force('charge', d3.forceManyBody().strength(-500)) // This adds repulsion (if it's negative) between nodes. .force('center', d3.forceCenter(width / 3, height / 3)).force( 'collision', d3.forceCollide().radius((d) => d.radius) ); postMessage(simulation); }; };
I'm getting an error

Uncaught ReferenceError: d3__WEBPACK_IMPORTED_MODULE_0__ is not defined at self.onmessage

cause by: import * as d3 from 'd3'; remove this and use @ts-ignore

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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