immutable-js-oss / immutable-js

Immutable persistent data collections for Javascript which increase efficiency and simplicity.
https://immutable-js-oss.github.io/immutable-js/
MIT License
37 stars 6 forks source link

ES6 import for Rollup Compatibility #58

Closed Methuselah96 closed 4 years ago

Methuselah96 commented 4 years ago

From @rbiggs on Fri, 10 Nov 2017 18:16:48 GMT

What happened

Trying to use ImmutableJS with Rollup as an es6 import. I have the Rollup plugin for CommonJS, which I've used for other CommonJS modules, no problem. However, when I try to incorporate ImmutableJS into a project, it doesn't get imported. I would expect to do something like this:

nom i -D immutable

Then in my app.js file, import it like so:

import {List} from 'immutable'

I have Rollup configured like this:

plugins: [
  babel(),
  resolve({
    jsnext: true,
    main: true,
    browser: true,
    module: true
  }),
  commonjs({
    include: [
      'node_modules/immutable/**'
    ],
    namedExports: { 'node_modules/immutable/dist/immutable.min.js': ['List'] }
  }),
  uglify({
    compress: {
      collapse_vars: true
    }
  })
]

However, when I build, I get the following error in the terminal:

node_modules/immutable/dist/immutable.js (10:3) The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
[10:04:04] 'build' errored after 2.93 s
[10:04:04] Error: 'List' is not exported by node_modules/immutable/dist/immutable.js

By the way, I had previously scoured the internet for other CommonJS issues with Rollup and tried various configurations, including ones that have previously worked for me. But non of these seem to work for ImmutableJS.

Note: I discovered that you do provide an ES6 compatible version if I download the source code and build locally. Then I can copy that into my project and import it as a normal es6 module:

import {List} from './utils/immutable.es'

Why isn't this included in the default install? It would be practical, I would think, to enable ImmutableJS to be installed and imported like a normal es6 module with Rollup without having to build it and then copying the es6 version manually. That just feels like Stone Age.

Copied from original issue: https://github.com/immutable-js/immutable-js/issues/1440

Methuselah96 commented 4 years ago

Resolved in v4.