简体   繁体   English

错误:在 /app/node_modules/chart.js/package.json 中没有使用 nextjs 和 chartjs 定义“导出”主要内容

[英]Error: No "exports" main defined in /app/node_modules/chart.js/package.json with nextjs and chartjs

I am trying to implement zoom behavior using nextjs, react-chartjs-2 and chartjs-plugin-zoom.我正在尝试使用 nextjs、react-chartjs-2 和 chartjs-plugin-zoom 实现缩放行为。

Here is my package.json:这是我的 package.json:

{
  "dependencies": {
    "@auth0/nextjs-auth0": "^2.0.1",
    "@fortawesome/fontawesome-free": "^6.2.1",
    "@types/node": "18.11.13",
    "@types/react": "18.0.26",
    "@types/react-dom": "18.0.9",
    "chart.js": "^4.0.1",
    "chartjs-plugin-zoom": "^2.0.0",
    "classnames": "^2.3.2",
    "eslint": "8.29.0",
    "eslint-config-next": "13.0.6",
    "next": "13.0.6",
    "nextjs-progressbar": "0.0.16",
    "react": "18.2.0",
    "react-chartjs-2": "^5.0.1",
    "react-cookie-consent": "^8.0.1",
    "react-dom": "18.2.0",
    "typescript": "4.9.4"
  },
  "devDependencies": {
    "@types/chart.js": "^2.9.37",
    "autoprefixer": "^10.4.13",
    "moment": "^2.29.4",
    "postcss": "^8.4.20",
    "tailwindcss": "^3.2.4"
  }
}

and my tsconfig.json和我的 tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext", "ES2015"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "helpers/index.js"],
  "exclude": ["node_modules"]
}

I believe there is some error on my compiler options on tsconfig.json but I couldn't figure it out.我相信我在 tsconfig.json 上的编译器选项有一些错误,但我无法弄清楚。

I didn't paste my chartjs code as to reproduce my problem, all I did was to register the zoom plugin like that:我没有粘贴我的 chartjs 代码来重现我的问题,我所做的只是像这样注册缩放插件:

import zoomPlugin from 'chartjs-plugin-zoom';

Chart.register(
  zoomPlugin
);

Here is you can reproduce the issue: https://stackblitz.com/edit/nextjs-yqgjsf?file=pages/index.js您可以在此处重现该问题: https ://stackblitz.com/edit/nextjs-yqgjsf?file=pages/index.js

After countless hours of trial and error, I fixed the error by registering plugins like this:经过无数小时的反复试验,我通过注册这样的插件来修复错误:

if (typeof window !== 'undefined') {
  (async () => {
    const { default: zoomPlugin } = await import('chartjs-plugin-zoom');
    Chart.register(
      zoomPlugin
    );
  })();
}

暂无
暂无

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

相关问题 依赖性甚至未在package.json和node_modules中定义 - Dependency Not found even defined in package.json and node_modules 错误:在 graphql-upload/package.json 中没有定义主要的“导出” - Error: No "exports" main defined in graphql-upload/package.json 弃用警告:在 node_modules\postcss\package.json 的 package 的“导出”字段模块解析中使用弃用的文件夹映射“./” - DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at node_modules\postcss\package.json 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:package.json 中没有定义“exports”main - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in package.json 本地 package.json 存在,但缺少 node_modules - Local package.json exists, but node_modules missing 在 Mongoose 中,找不到模块 '\node_modules\ipaddr.js\lib\ipaddr.js'。 请确认 package.json 具有有效的“主”条目 - In Mongoose, can't find module '\node_modules\ipaddr.js\lib\ipaddr.js'. Please verify that the package.json has a valid “main” entry 如何解决包子路径 './package.json' is not defined by "exports" 错误 - How to resolve Package subpath './package.json' is not defined by "exports" error 错误:“/app/node_modules/uuid”的 Package 导出未定义有效的“。” 目标 - Error: Package exports for '/app/node_modules/uuid' do not define a valid '.' target “没有出口主要定义在”错误Node.js - "No Exports Main Defined In" Error Node.js 如何在docker构建期间的yarn / npm安装期间缓存node_modules以获取未更改的package.json - How to cache node_modules for unchanged package.json during yarn / npm install during docker build?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM