【发布时间】:2023-02-10 04:13:07
【问题描述】:
我已经设置了一个 Next13 typescript 应用程序。在这里面,我试图在 Mapbax 底图上渲染一个 deckgl arclayer。
const Page = () => {
const data = [{ sourcePosition: [-122.41669, 37.7853], targetPosition: [-122.41669, 37.781] }];
const isClient = typeof window !== 'undefined';
const layer = isClient
? new ArcLayer({
id: 'arc-layer',
migration,
pickable: true,
getWidth: (d: AreaMigration) => d.moves_estimated / 10,
getSourcePosition: (d: AreaMigration) => states[d.origin_us_state],
getTargetPosition: (d: AreaMigration) => states[d.destination_us_state],
//@ts-ignore
getSourceColor: (d: AreaMigration) => [...hexToRgb(Primary.Primary01), 255],
//@ts-ignore
getTargetColor: (d: AreaMigration) => [...hexToRgb(Secondary.Secondary01), 125],
})
: undefined;
return (
<MapboxPageStyled>
{isClient && (
<DeckGL
initialViewState={INITIAL_VIEW_STATE}
controller={true}
style={{ width: '100%', height: '100%', borderRadius: '3px', overflow: 'hidden' }}
layers={[layer]}
>
<ReactMapGL />
</DeckGL>
)}
<Paragraph>{migration[0].origin_area}</Paragraph>
</MapboxPageStyled>
);
};
构建页面时出现错误
warn - ./node_modules/@loaders.gl/worker-utils/dist/es5/lib/node/require-utils.node.js Critical dependency: the request of a dependency is an expression
我修改了 next-config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
experimental: { appDir: true, esmExternals: 'loose' },
transpilePackages: ['@loaders.gl', '@probe.gl'],
};
module.exports = nextConfig;
并已在页面上启用客户端呈现。
所有帮助表示赞赏!
我也尝试在 arclayer 和 deckgl 上使用动态导入功能但没有成功。
【问题讨论】:
标签: reactjs next.js server-side-rendering deck.gl nextjs13