Skip to content

Circular dependency error with rollup for browser #291

@jdesrosiers

Description

@jdesrosiers

Describe the bug
When bundling yaml for the browser using rollup, I get a circular dependency error. This seems to be a quirk (maybe even a bug?) of the way rollup builds for the browser. A small tweak seems to solve the problem.

Change this,

import * as YAML from './dist/index.js'

to this,

import * as YAML from '../browser/dist/index.js'

To Reproduce
Here's a minimal reproduction.

package.json

{
  "scripts": {
    "build": "rollup -c"
  },
  "dependencies": {
    "@rollup/plugin-commonjs": "^19.0.0",
    "@rollup/plugin-node-resolve": "^13.0.0",
    "rollup": "^2.52.4",
    "yaml": "^2.0.0-6"
  }
}

rollup.config.js

const { nodeResolve } = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");


module.exports = {
  input: "index.js",
  output: {
    format: "iife",
    file: "dist.js",
    name: "Test",
    exports: "auto"
  },
  plugins: [
    nodeResolve({
      browser: true
    }),
    commonjs(),
  ]
};

index.js

const YAML = require("yaml");
  
const data = YAML.parse(`foo: bar`);
console.log(data);

Run rollup with npm run build. You should see the circular dependency error. Make the change suggested above (or a better one if it exists) and the error goes away and you can run the bundled app with node dist.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions