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
501 stars 126 forks source link

Error: 'tslib' is imported as an external by tslib?commonjs-proxy, but is already an existing non-external module id. #413

Closed themaskedavenger closed 4 years ago

themaskedavenger commented 4 years ago

I'm trying to make an all-in bundled application that can run off of just 1 file. When I run rollup I get this error:

Error: 'tslib' is imported as an external by tslib?commonjs-proxy, but is already an existing non-external module id.

tslib is not imported directly by any of my application's code, so this is just a dependency within a dependency. Is there some flag to prevent this error? Also, what is the ?commonjs-proxy there? Is this some kind of circular dependency?

Using typescript, resolve, commonjs, and json plugins.

TrySound commented 4 years ago

Please provide rollup config

themaskedavenger commented 4 years ago

Ah sorry, it's roughly this:


import json from 'rollup-plugin-json';
import nodeBuiltins from 'rollup-plugin-node-builtins';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';

export default {
  input: 'src/runServer.ts',
  output: {
    file: 'dist/build/runServer.js',
    format: 'umd',
  },
  plugins: [
    nodeBuiltins(),
    typescript(),
    resolve(),
    commonjs(),
    json(),
  ],
};```
themaskedavenger commented 4 years ago

I have tried different formats to no avail

TrySound commented 4 years ago

Try to remove rollup-plugin-node-builtins

GongT commented 4 years ago

Typescript should after resolve.


When I use rollup-plugin-ignore, I got:

[src] (!) Unresolved dependencies
[src] https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
[src] empty_module (imported by empty_module?commonjs-proxy)
[src] [!] Error: 'empty_module' is imported as an external by empty_module?commonjs-proxy, but is already an existing non-external module id.
[src] Error: 'empty_module' is imported as an external by empty_module?commonjs-proxy, but is already an existing non-external module id.
[src]     at error (/data/DevelopmentRoot/canaan-creative/door/admin/app/node_modules/rollup/dist/rollup.js:10162:30)
[src]     at ModuleLoader.fetchResolvedDependency (/data/DevelopmentRoot/canaan-creative/door/admin/app/node_modules/rollup/dist/rollup.js:17226:24)
[src]     at ModuleLoader.<anonymous> (/data/DevelopmentRoot/canaan-creative/door/admin/app/node_modules/rollup/dist/rollup.js:17286:25)
[src]     at Generator.next (<anonymous>)
[src]     at fulfilled (/data/DevelopmentRoot/canaan-creative/door/admin/app/node_modules/rollup/dist/rollup.js:40:28)
TrySound commented 4 years ago

Why ignore plugin? What are you trying to achieve? Do you build for node or for browser?

GongT commented 4 years ago

For browser, My goal is replace some buggy module with my custom one. So I want to ignore them and use System.register to replace it.

TrySound commented 4 years ago

You can use rollup for that and prevent pollution runtime with this library.

{
  resolveId(importee, importer) {
    if (importee === 'broken-lib') {
      return this.resolve(path.join(__dirname, './fixed-lib.js'), importer);
    }
  }
}
themaskedavenger commented 4 years ago

I've tried it without rollup-plugin-node-builtins, same error.

themaskedavenger commented 4 years ago

What does this error mean, exactly?!

TrySound commented 4 years ago

Could you create repo with the error you facing?

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: