rollup / rollup-plugin-commonjs

This module has moved and is now available at @rollup/plugin-commonjs / https://github.com/rollup/plugins/blob/master/packages/commonjs
MIT License
502 stars 126 forks source link

import domain from 'domain'; import getting added from react-dnd #297

Closed arackaf closed 4 years ago

arackaf commented 6 years ago

This was originally posted here: https://github.com/rollup/rollup/issues/2013#issuecomment-369349854

But this repo seems to be a better place for it.


Repo: https://github.com/arackaf/booklist/tree/special/rollup-snapshot-feb-25 (that branch in particular)

Switch to the react-redux folder. npm i npm run ts then finally npm run rollup

In public/module/subjects.js note the following line:

import domain from 'domain';

which of course causes errors. I've tracked this down to the react-dnd library. If you go into react-redux/modules/subjects/components/subjectsList.js (NOT the typescript companion) and remove

import { DragSource, DragDropContext, DropTarget, DragLayer } from "react-dnd";

and then re-run rollup (but NOT TypeScript) the import vanishes.

I peaked down into the react-dnd source, and the only mention of the word domain was in a code comment.

arackaf commented 6 years ago

@guybedford subsequently added this update:

I just had a look at this case and import domain from 'domain' seems to appear so long as one is running the CommonJS Rollup plugin against node_modules/react-dnd/lib/index.js with any normal Rollup operation.

So basically:

import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";

export default {
    input: "./node_modules/react-dnd/lib/index.js",
    output: {
      file: "public/module/out.js",
      format: "es",
      sourcemap: false
    },
    plugins: [commonjs(), resolve()]
  }
}

is the minimal replication I was able to get here.

It should be possible to further isolate if it is react-dnd itself or a dependency of react-dnd bringing in domain.

I don't have a deep knowledge of how these Rollup plugins work so it may be worth posting an issue there further. I tend to use my own NodeJS Rollup plugin for this stuff which I'm hoping to make available publicly soon.

guybedford commented 6 years ago

I assume react-dnd is itself needing domain here?

If so, try installing domain-browserify and configuring domain to load from that using eg the alias plugin - https://github.com/rollup/rollup-plugin-alias.

arackaf commented 6 years ago

@guybedford thanks for the info. I'm not quite looking to move this app to Rollup just yet, so this case was more to document this bug in the hopes that a general solution might be found, for the benefit of Rollup.

swederik commented 5 years ago

For anyone else arriving at this issue, I found that the rollup-plugin-alias solution unfortunately did not work.

I managed to resolve the domain issue caused by react-dnd usage by adding rollup-plugin-node-builtins.

shellscape commented 4 years ago

Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid. We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets transferred to the new repo. :beer: