Далее Js + amcharts: ошибка производственной сборки: ReferenceError: addEventListener не определен - PullRequest
0 голосов
/ 18 июня 2020

Я работаю над следующим проектом js и использую библиотеку amcharts.

Когда я создаю производственную сборку, я получаю ошибку ниже.

> Build error occurred
{ ReferenceError: addEventListener is not defined
    at new Registry (D:\XKDashboardClient\.next\server\static\FsJlbi7eD-pYXPY5IEwnp\pages\patientDetails.js:4945:9)
    at Module.u55L (D:\XKDashboardClient\.next\server\static\FsJlbi7eD-pYXPY5IEwnp\pages\patientDetails.js:5159:16)
    at __webpack_require__ (D:\XKDashboardClient\.next\server\static\FsJlbi7eD-pYXPY5IEwnp\pages\patientDetails.js:29:31)
    at Object.11 (D:\XKDashboardClient\.next\server\static\FsJlbi7eD-pYXPY5IEwnp\pages\patientDetails.js:334:18)
    at __webpack_require__ (D:\XKDashboardClient\.next\server\static\FsJlbi7eD-pYXPY5IEwnp\pages\patientDetails.js:29:31)
    at D:\XKDashboardClient\.next\server\static\FsJlbi7eD-pYXPY5IEwnp\pages\patientDetails.js:124:18
    at Object.<anonymous> (D:\XKDashboardClient\.next\server\static\FsJlbi7eD-pYXPY5IEwnp\pages\patientDetails.js:127:10)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32) type: 'ReferenceError' }
Automatically optimizing pages .npm ERR! code ELIFECYCLE

Вот мой файл next.config . js файл

const withCSS = require("@zeit/next-css");
const withImages = require("next-images");
const withFonts = require("nextjs-fonts");
const withTM = require("next-transpile-modules")([
  "react-native-vector-icons",
  "@amcharts/amcharts4/core",
  "@amcharts/amcharts4/charts",
  "@amcharts/amcharts4/themes/animated",
]); // pass the modules you would like to see transpiled


module.exports = withCSS(
  withTM(
      withImages(
        withFonts({
          /* config options here */
          env: {
            API_URL: "http://localhost:4000/api/",
            SOCKET_URL: "http://localhost:4000/",
          },
        })
    )
  )
);

Если я закомментирую код ниже, он работает и без ошибок. этот код - node_modules@amcharts \ amcharts4.internal \ core \ Registry. js enter image description here

ОБНОВЛЕНИЕ

Я исправил ошибка сборки путем удаления amcharts из файла webpack. и импортируйте его, как показано ниже, при загрузке страницы.

let am4core = null;
let am4charts = null;
let am4themesAnimated = null;
if (process.browser) {
  console.log("process.browser", process.browser);
  am4core = require("@amcharts/amcharts4/core");
  am4charts = require("@amcharts/amcharts4/charts");
  am4themesAnimated = require("@amcharts/amcharts4/themes/animated");
  am4core.useTheme(am4themesAnimated.default);
}

Теперь моя сборка продукта работает нормально, и диаграмма загружается нормально при первой загрузке. Когда я обновляю sh страницу, она показывает мне ошибку ниже:

charts.js:1 Uncaught ReferenceError: am4internal_webpackJsonp is not defined
    at charts.js:1
(anonymous) @ charts.js:1
maps.js:1 Uncaught ReferenceError: am4internal_webpackJsonp is not defined
    at maps.js:1
...