reselect icon indicating copy to clipboard operation
reselect copied to clipboard

Dist version of reselect via npm install may be incorrect.

Open andrewmtam opened this issue 9 years ago • 6 comments

Hiya,

I am using your reselect module for a project that is setup on requireJS ( with an es6 plugin, sorry if that confuses things). In the dist file that is included, when 'define' is defined, you are doing this:

define('Reselect', ['exports'], factory);

What that means is that in order for me to use this module, I have to do this:

import 'libs/reselect'; import { createFunction } from 'Reselect';

However, if you just change your dist file to read:

define(['exports'], factory);

then I can import this library the way I expect to:

import { createFunction } from 'libs/reselect';

Let me know if that's correct, or if I am doing something wrong. Thanks!

andrewmtam avatar Mar 25 '17 02:03 andrewmtam

I'm having the same problem when importing with TypeScript and tsconfig.json module format is amd and no bundling, so Typescript outputs individual files

(typescript file) import * as reselect from 'reselect';

I have to change it to the following for it to work import * as reselect from 'Reselect';

Redux and other Redux libraries do not define with a name in amd mode.

madaz avatar May 22 '17 22:05 madaz

Does someone with requireJS experience want to take ownership of this issue?

ellbee avatar May 23 '17 18:05 ellbee

define(['exports'], factory); instead of define('Reselect', ['exports'], factory);

in the UMD module fixes the problem of requirejs define import

p10ns11y avatar Jun 20 '17 11:06 p10ns11y

this can also be worked around by using the map and paths fields of require.config():

require.config({
  map: {
    // apply these maps for all modules
    '*': {
      // when "reselect" is requested, use the module named "Reselect" instead
      'reselect': 'Reselect'
    }
  },
  paths: {
    // specify the path to reselect.js as the path for the aliased Reselect module
    // (don't forget to leave off the .js file extension, like the docs say)
    Reselect: 'path/to/reselect/dist/reselect'
  }
});

orzechowskid avatar Jul 14 '17 14:07 orzechowskid

Looking into this more, maybe this should be a feature request for this plugin:

https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-umd

and having more control over the names of the exported module ( similar to what webpack does I think [ https://github.com/webpack/webpack/tree/master/examples/externals ] )

Otherwise, when a moduleId is specified in the .babelrc file: https://github.com/reactjs/reselect/blob/master/.babelrc#L21

that ID gets used for all the module types in the UMD file (amd, commonjs, commonjs2, etc...).

If no ID is set, it looks like it defaults to using the file name of the entry file ('index' in our case).

One solution would be to remove the moduleID from the .babelrc, and then rename the entry file from index.js to reselect.js. Or, possibly just rename the moduleID to 'reselect' instead of 'Reselect'?

andrewmtam avatar Jul 15 '17 00:07 andrewmtam

Closing on the grounds that the issue is stale, and AMD support is not sufficiently relevant today.

markerikson avatar Feb 07 '21 18:02 markerikson