首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用带有Formik的Rollup.JS的外部库不尊重命名导出

使用带有Formik的Rollup.JS的外部库不尊重命名导出
EN

Stack Overflow用户
提问于 2019-11-28 09:34:16
回答 3查看 1.4K关注 0票数 7

我使用汇总将表单组件的共享库组合在一起,该库使用Formik作为基本层。目前,我收到了下面的“调度程序”编译错误,这是Formik在幕后使用的。

我尝试过手动安装它作为一个单独的npm依赖项,但是仍然会得到以下错误。

代码语言:javascript
复制
[!] Error: 'unstable_runWithPriority' is not exported by node_modules/formik/node_modules/scheduler/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/formik/dist/formik.esm.js (9:9)
 7: import toPath from 'lodash-es/toPath';
 8: import invariant from 'tiny-warning';
 9: import { unstable_runWithPriority, LowPriority } from 'scheduler';

遵循汇总文档:我尝试使用rollup.config.js的命名导出部分,例如:

代码语言:javascript
复制
plugins: [


    peerDepsExternal(),
    postcss({ extract: true, plugins: [autoprefixer] }),
    json({  include: 'node_modules/**' }),
    babel({ exclude: 'node_modules/**', presets: ['@babel/env', '@babel/preset-react'] }),
    localResolve(),
    resolve({dedupe: [ 'react', 'react-dom' ]}),
    commonjs({
      namedExports: {
        // left-hand side can be an absolute path, a path
        // relative to the current directory, or the name
        // of a module in node_modules
        'node_modules/formik/node_modules/scheduler/index.js': ['unstable_runWithPriority'],
        'scheduler': ['unstable_runWithPriority'],
        'node_modules/scheduler': ['unstable_runWithPriority'],
        './node_modules/scheduler': ['unstable_runWithPriority'],
        '../node_modules/formik/node_modules/scheduler/index.js': ['unstable_runWithPriority']
      }
    }),
    globals(),
    externals(),
    builtins(),
    filesize()

  ]

如您所见,我尝试了几个目的地/路径,以获得良好的效果。有谁能为我指出正确的方向,如何重新获得这个编译?或者如何正确定义我的命名导出?我在网络上读到了一些问题,这些问题表明插件数组的顺序可能会影响事物,但我交换了一些,但我仍然感到困惑。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-11-28 11:32:47

你可能认为地球上没有人会犯同样的错误。你就错了。找到了解决办法。(这与插件上的顺序有关)

代码语言:javascript
复制
plugins: [
    globals(),
    builtins(),
    externals(),
    babel({ exclude: 'node_modules/**', presets: ['@babel/env', '@babel/preset-react'] }),
    commonjs({
      namedExports: {
        // left-hand side can be an absolute path, a path
        // relative to the current directory, or the name
        // of a module in node_modules
        'node_modules/formik/node_modules/scheduler/index.js' : ['unstable_runWithPriority'],
      }
    }),
    peerDepsExternal(),
    postcss({ extract: true, plugins: [autoprefixer] }),
    json({  include: 'node_modules/**' }),
    localResolve(),
    resolve({dedupe: [ 'react', 'react-dom' ]}),
    filesize()

  ]
票数 5
EN

Stack Overflow用户

发布于 2020-06-04 02:06:44

这个插件命令为我解决了这个问题。

代码语言:javascript
复制
plugins: [
    babel({
      exclude: 'node_modules/**',
      presets: ['@babel/env', '@babel/preset-react'],
    }),
    typescript({ useTsconfigDeclarationDir: true }),
    commonjs({
      namedExports: {
        // left-hand side can be an absolute path, a path
        // relative to the current directory, or the name
        // of a module in node_modules
        'node_modules/formik/node_modules/scheduler/index.js': [
          'unstable_runWithPriority',
        ],
      },
    }),
    peerDepsExternal(),
    scss(),
    json({
      compact: true,
    }),
    resolve(),
  ],
票数 0
EN

Stack Overflow用户

发布于 2020-09-07 19:46:08

使用以下语法:

代码语言:javascript
复制
      namedExports: {
        'scheduler': ['unstable_runWithPriority', 'unstable_LowPriority']
      }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59085618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档