piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 99 forks source link

Error: 'createAction' is not exported by typesafe-actions.umd.production.js #250

Closed lukemorales closed 2 years ago

lukemorales commented 3 years ago

Description

I'm building my react project with rollup, and because of some libs I need to activate browser: true on rollup-node-resolver, but I cannot build my app because of the following error: [!] Error: 'createAction' is not exported by node_modules/typesafe-actions/dist/typesafe-actions.umd.production.js

Mandatory info

How to Reproduce

No CodeSandbox Link

If no codesandbox, then please provide a full working code example below including actions, reducers and your custom types used in the example.

Below is the rollup config file

import pkg from '../../package.json'

import postcss from 'rollup-plugin-postcss'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import commonjs from 'rollup-plugin-commonjs'
import url from '@rollup/plugin-url'
import typescript from 'rollup-plugin-typescript2'
import babel from 'rollup-plugin-babel'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import { terser } from 'rollup-plugin-terser'
import svgr from '@svgr/rollup'

import dotenv from 'dotenv-flow'
dotenv.config()

export default [
  {
    input: './src/index.tsx',
    external: Object.keys(pkg.peerDependencies),
    output: {
      name: 'InterFrontEndCDPROPixExtrato',
      file: 'lib/index.js',
      format: 'umd',
      sourcemap: false,
    },
    plugins: [
      postcss({
        extract: true,
        minimize: true,
        sourceMap: false,
      }),
      replace({
        'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
        'process.env.BASE_URL': JSON.stringify(process.env.BASE_URL),
        'process.env.NEW_RELIC_ACCOUNT': JSON.stringify(process.env.NEW_RELIC_ACCOUNT),
        'process.env.NEW_RELIC_KEY': JSON.stringify(process.env.NEW_RELIC_KEY),
      }),
      url({
        limit: 0,
        destDir: 'lib/assets/',
        publicPath: process.env.BASE_CDN.replace(/\/(alpha|beta|latest)/i, '') + '/assets/',
      }),
      svgr(),
      peerDepsExternal(),
      terser(),
      babel({
        exclude: [ 'example/', 'config/' ],
        runtimeHelpers: true,
      }),
      nodeResolve({
        browser: true <<< when activating this rule, the app build breaks
      }),
      commonjs(),
      typescript({
        typescript: require('ttypescript'),
        tsconfigDefaults: {
          compilerOptions: {
            plugins: [
              { "transform": "typescript-transform-paths" },
              { "transform": "typescript-transform-paths", "afterDeclarations": true }
            ]
          }
        }
      }),,
    ],
  },
]

Below is how i'm using the createAction function:

import { createAction } from 'typesafe-actions'

export const setFilterDates = createAction(
  '@steps/SET_FILTER_DATES',
  (initialDate: Date, finalDate: Date) => ({
    initialDate,
    finalDate,
  }),
)<{ initialDate: Date; finalDate: Date }>()

export const setDatesInterval = createAction(
  '@steps/SET_DATES_INTERVAL',
  (interval: number = 7) => ({
    interval,
  }),
)<{ interval: number }>()

Expected behavior

It should build the app with typesafe-actions scripts

Suggested solution(s)

Verify if the umd files are indeed exporting all functions the lib provides.

Project Dependencies

Environment (optional)