omnidan / redux-undo

:recycle: higher order reducer to add undo/redo functionality to redux state containers
MIT License
2.91k stars 188 forks source link

Can't import 1.0.1 using ES6 module syntax. #269

Closed verhovsky closed 4 years ago

verhovsky commented 4 years ago

I yarn add redux-undo'd, version ^1.0.1 and tried to import it

import { ActionCreators } from 'redux-undo';

I get this error:

Uncaught (in promise) SyntaxError: The requested module '../../../node_modules/redux-undo/lib/index.js' does not provide an export named 'ActionCreators'

If I look at that file, it looks like this

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ActionCreators = exports.ActionTypes = void 0;
var ActionTypes = {
  UNDO: '@@redux-undo/UNDO',
  REDO: '@@redux-undo/REDO',
  JUMP_TO_FUTURE: '@@redux-undo/JUMP_TO_FUTURE',
  JUMP_TO_PAST: '@@redux-undo/JUMP_TO_PAST',
  JUMP: '@@redux-undo/JUMP',
  CLEAR_HISTORY: '@@redux-undo/CLEAR_HISTORY'
};
exports.ActionTypes = ActionTypes;
var ActionCreators = {
  undo: function undo() {
    return {
      type: ActionTypes.UNDO
    };
  },
  redo: function redo() {
    return {
      type: ActionTypes.REDO
    };
  },
  jumpToFuture: function jumpToFuture(index) {
    return {
      type: ActionTypes.JUMP_TO_FUTURE,
      index: index
    };
  },
  jumpToPast: function jumpToPast(index) {
    return {
      type: ActionTypes.JUMP_TO_PAST,
      index: index
    };
  },
  jump: function jump(index) {
    return {
      type: ActionTypes.JUMP,
      index: index
    };
  },
  clearHistory: function clearHistory() {
    return {
      type: ActionTypes.CLEAR_HISTORY
    };
  }
};

Is something wrong with my setup or are you building the releases wrong? If I go to https://www.npmjs.com/package/redux-undo and click Try on RunKit it's imported using require('redux-undo') and the file also doesn't look like an ES6 module https://npm.runkit.com/redux-undo/es/actions.js?t=1586799334448

nmay231 commented 4 years ago

You should be able to import redux-undo using ES6 modules perfectly fine. RunKit launches a Node environment which is why the imports still use require().

I just installed it in one of my projects using yarn v1.22.4 and it looked like it built it correctly.

Object.defineProperty(exports, "ActionTypes", {
  enumerable: true,
  get: function get() {
    return _actions.ActionTypes;
  }
});
Object.defineProperty(exports, "ActionCreators", {
  enumerable: true,
  get: function get() {
    return _actions.ActionCreators;
  }
});

// ...

var _actions = require("./actions");

I would try a simple uninstall/reinstall real quick. If the problem persists, please list your tooling versions and enviroment: yarn, webpack, operating system, etc.

verhovsky commented 4 years ago

Sorry, I pasted the contents of actions.js, my index.js looks like what you posted. I'm using

$ node --version
v12.14.0
$ yarn --version
1.22.4
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
Codename:       bionic

I'm not using webpack or rollup or anything.

This is code running in the browser, Chrome 81

verhovsky commented 4 years ago

Is this because everyone is expected to be using a bundler? I made it work by copy and pasting cloning the repo into my code and doing import undoable from 'path/to/js/redux-undo/src/index.js