简体   繁体   English

图表 v4:找不到模块:错误:Package 路径。 不从 package node_modules/chart.js 导出

[英]Chart v4 : Module not found: Error: Package path . is not exported from package node_modules/chart.js

I'm maintaining a react component library that uses chart.js as a dependency (Not peerDependency).我正在维护一个使用 chart.js 作为依赖项(不是 peerDependency)的反应组件库。

I upgraded chart.js from 3.9.1 to 4.0.1.我将 chart.js 从 3.9.1 升级到 4.0.1。

My library still compiles fine but now it throws an error on my react app when I'm importing the lib:我的库仍然可以正常编译,但现在当我导入库时,它会在我的 React 应用程序上引发错误:

Module not found: Error: Package path. is not exported from package node_modules/chart.js

I'm building everything with rollup here is my config:我正在使用 rollup 构建所有内容,这是我的配置:

import path from 'path';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import postcss from 'rollup-plugin-postcss';
import typescript from '@rollup/plugin-typescript';
import image from '@rollup/plugin-image';
import json from '@rollup/plugin-json';
import copy from 'rollup-plugin-copy';
import autoprefixer from 'autoprefixer';
import postcssUrl from 'postcss-url';
import pkg from './package.json' assert { type: 'json' };
import {fileURLToPath} from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const { dependencies = {}, peerDependencies = {} } = pkg;

const externals = [...Object.keys(dependencies), ...Object.keys(peerDependencies)];

const src = path.resolve(__dirname, 'src');
const input = path.resolve(src, 'index.ts');
const assets = path.resolve(src, 'assets');
const dest = path.resolve(__dirname, 'dist');

export default [
  {
    input,
    external: (id) => externals.some((dep) => id === dep || id.startsWith(`${dep}/`)),
    plugins: [
      typescript({ tsconfig: './tsconfig.json' }),
      commonjs(),
      json(),
      resolve({ browser: true }),
      babel({
        extensions: ['.ts', '.js', '.tsx', '.jsx'],
      }),
      image(),
      postcss({
        plugins: [
          autoprefixer,
          postcssUrl({
            url: 'inline',
            basePath: assets,
          }),
        ],
      }),
      copy({
        targets: [
          { src: 'src/**/_*.scss.d.ts', dest },
          { src: 'src/**/_*.scss', dest },
        ],
      }),
    ],
    output: [
      {
        file: pkg.main,
        format: 'cjs',
      },
      { name: pkg.name, file: pkg.module, format: 'es' },
      {
        name: pkg.name,
        file: pkg.browser,
        format: 'umd',
        globals: {
          react: 'React',
        },
      },
      {
        name: pkg.name,
        file: pkg['browser:min'],
        format: 'umd',
        globals: {
          react: 'React',
        },
        plugins: [terser()],
      },
    ],
  },
];

Does someone has any idea why it is doing so?有人知道为什么要这样做吗?

I tried to delete node_modules and package-lock.json and reinstall both on my library and front app but I still have the same error.我试图删除 node_modules 和 package-lock.json 并在我的库和前端应用程序上重新安装,但我仍然有同样的错误。

I tried to import from 'chart.js/auto' as mentioned in the documentation but it throws:我尝试按照文档中所述从“chart.js/auto”导入,但它抛出:

Module not found: Error: Package path./auto is not exported from package node_modules/chart.js

I looked at node_modules/chart.js/package.json file and there is a well defined set of exports there.我查看了 node_modules/chart.js/package.json 文件,那里有一组定义明确的导出。 But as it came with the upgrade and no other library has ever throw me this error I guess it comes from the upgrade.但是由于它伴随着升级而来,而且没有其他图书馆向我抛出这个错误,我猜它来自升级。

Found the bug.发现了错误。 As I thought it is a problem with the library itself.我认为这是图书馆本身的问题。 It cannot be required since the conditional subpath is missing from the package.json file.它不是必需的,因为 package.json 文件中缺少条件子路径。 Nothing I can do.我无能为力。 I'll downgrade untill the push a fix.我会降级,直到推动修复。

暂无
暂无

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

相关问题 错误:在 /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 未找到模块:包路径 ./react 未从包 E:\\NextApp\\portfolio_website-main\\portfolio_website-main\\node_modules\\next-auth 导出 - Module not found: Package path ./react is not exported from package E:\NextApp\portfolio_website-main\portfolio_website-main\node_modules\next-auth 找不到模块:包路径。 不从包中导出 - Module not found: Package path . is not exported from package 在 Chart.js 中使用 package - Utils package in Chart.js 错误 in./src/firebase.config.js 6:0-53 未找到模块:错误:Package 路径。/getFirestore 未从 package 导出 - ERROR in ./src/firebase.config.js 6:0-53 Module not found: Error: Package path ./getFirestore is not exported from package 找不到文件:“Chart.js”与磁盘上的相应名称不匹配:“.\node_modules\chart.js\dist\chart.js” - Cannot find file: 'Chart.js' does not match the corresponding name on disk: '.\node_modules\chart.js\dist\chart.js' 如何解决此 firebase 导入错误? 找不到模块:错误:Package 路径。 不从 package 导出 - How do I resolve this firebase import error? Module not found: Error: Package path . is not exported from package 找不到模块:错误:在角度更新到 13 后,包路径 ./locales 未从包中导出 - Module not found: Error: Package path ./locales is not exported from package after angular update to 13 node_modules 中的节点 js MODULE_NOT_FOUND 错误 - node js MODULE_NOT_FOUND error in node_modules 从 node_modules 获取精确依赖的路径 package - Get path of exact dependency from node_modules package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM