簡體   English   中英

由於 plotly.js,Next.js 紗線構建失敗(發生構建錯誤 ReferenceError: self is not defined)

[英]Next.js yarn build failed due to plotly.js (Build error occurred ReferenceError: self is not defined)

當我嘗試使用yarn build命令yarn build用於生產的 Next.js 應用程序時,出現以下錯誤。 但它在開發服務器中運行良好(使用yarn dev命令時)。 我正在使用react-plotly.js庫在這個 react 應用程序中生成繪圖圖。

react-plotly 庫的使用:

import Plot from 'react-plotly.js';

return(
  <>
   <Plot data={[data]} layout={layout} />
  </>
)

這是錯誤:

> Build error occurred
ReferenceError: self is not defined

在此處輸入圖片說明

我研究了 plotly.js git repository 和 google 類似問題上的問題,但似乎沒有結果。 為什么 Next.js 紗線構建失敗的任何想法?

Next Js 使用服務器端渲染並且在本地開發時仍然模擬 ssr,因此許多依賴於本機對象(通常是窗口對象)的庫將無法按預期工作。

https://github.com/plotly/react-plotly.js/issues/40

似乎 plotly 不適用於 ssr 但還有另一個組件應該https://github.com/aulneau/next.js-with-react-plotly.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM