Ошибка накопления: isValidElementType не экспортируется в node_modules / реагировать-is / index.js - PullRequest
0 голосов
/ 28 апреля 2018

Я собираю пакет с RollUp, используя styled-компоненты.

Мой rollup.config.js выглядит так:

import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  },
  external: [
    'react',
    'react-proptypes'
  ],
  plugins: [
    resolve({
      extensions: [ '.js', '.json', '.jsx' ]
    }),
    commonjs({
      include: 'node_modules/**'
    }),
    babel({
      exclude: 'node_modules/**'
    })
  ]
}

И я получаю

[!] Error: 'isValidElementType' is not exported by node_modules/react-is/index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
node_modules/styled-components/dist/styled-components.es.js (7:9)
5: import stream from 'stream';
6: import PropTypes from 'prop-types';
7: import { isValidElementType } from 'react-is';
            ^
8: import hoistStatics from 'hoist-non-react-statics';

Проверка самих узлов node_modules реагировать - это модуль commonjs, так как его можно также проверить здесь .

Не должен ли плагин commonjs позаботиться об этом, поскольку он находится внутри node_modules / **?

Спасибо.

Ответы [ 2 ]

0 голосов
/ 22 октября 2018

Исправление выше не сработало для меня. Однако добавление styled-components к списку внешних и глобальных rollup.config.js сработало для меня.

    export default {
      ...
      external: ['styled-components'],
      ...
      globals: { 'styled-components': 'styled' },
    };

Я использую машинопись create-реагировать-библиотека cli, которая поставляется в комплекте с накопительным пакетом.

https://github.com/styled-components/styled-components/issues/930

0 голосов
/ 30 апреля 2018

Я решил это с помощью rollup-plugin-commonjs

и определение экспорта вручную в конфигурации накопительного пакета, как показано ниже

export default {
  input: 'src/index.js',
  output: [
    {
      file: pkg.main,
      format: 'cjs',
      sourcemap: true
    },
    {
      file: pkg.module,
      format: 'es',
      sourcemap: true
    }
  ],
  plugins: [
    external(),
    postcss({
      modules: true
    }),
    url(),
    babel({
      exclude: 'node_modules/**'
    }),
    resolve(),
    commonjs({
      include: 'node_modules/**',
      namedExports: {
        'node_modules/react-is/index.js': ['isValidElementType']
      }
    })
  ]
}

После этого все работало нормально.

и для информации, моя первоначальная настройка была сделана через https://github.com/transitive-bullshit/react-modern-library-boilerplate

Надеюсь, у вас это получится

...