socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Circular dependency when bundling

Open falfab opened this issue 3 years ago • 3 comments

Description I am trying to bundle my library which has Socket.IO as a dependency. I am using rollup.js as a module bundler. When bundling it gives me the following error:

(!) Circular dependencies
node_modules/socket.io/dist/socket.js -> node_modules/socket.io/dist/broadcast-operator.js -> node_modules/socket.io/dist/socket.js
node_modules/socket.io/dist/socket.js -> node_modules/socket.io/dist/broadcast-operator.js -> <my_library_path>/node_modules/socket.io/dist/socket.js?commonjs-proxy -> node_modules/socket.io/dist/socket.js

To Reproduce

Socket.IO version: 4.4.1

Currently using this rollup config file:

import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript'
import dts from 'rollup-plugin-dts'
import postcss from 'rollup-plugin-postcss'
import { terser } from 'rollup-plugin-terser'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import json from '@rollup/plugin-json'

const packageJson = require('./package.json')

export default [
  {
    input: 'src/index.ts',
    output: [
      {
        file: packageJson.main,
        format: 'cjs',
        sourcemap: true,
      },
      {
        file: packageJson.module,
        format: 'esm',
        sourcemap: true,
      },
    ],
    plugins: [
      peerDepsExternal(),
      resolve(),
      commonjs(),
      typescript({ tsconfig: './tsconfig.json' }),
      postcss(),
      terser(),
      json({compact: true}),
    ],
  },
  {
    input: 'dist/esm/types/index.d.ts',
    output: [{ file: 'dist/index.d.ts', format: 'esm' }],
    plugins: [dts()],
    external: [/\.(css|less|scss)$/, 'websocket'],
  },
]

The warning message shows when executing:

npx rollup -c

Expected behavior No warning is shown

Platform:

  • OS: Ubuntu 20.04

falfab avatar Apr 01 '22 08:04 falfab

There is indeed a circular dependency between the source files. Let's fix that.

darrachequesne avatar Apr 05 '22 06:04 darrachequesne

I am getting the same warning for my application. Is this a problem when running the bundled js with nodejs? I have not seen any a errors in runtime so far.

steffenraubvogel avatar Apr 10 '23 11:04 steffenraubvogel

has this been resolved at all? i'm on 4.7.2 and still see this issue.

b1lly avatar Dec 10 '23 02:12 b1lly