Skip to content

camille-hdl/rollup-node-resolve-bug-yaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rollup-plugin-node-resolve bug

  • npm install
  • npm run build
  • npm run serve

Circular dependency warning:

(!) Circular dependency
node_modules/yaml/browser/dist/schema/Collection.js -> node_modules/yaml/browser/dist/schema/Pair.js -> node_modules/yaml/browser/dist/schema/Collection.js

Bug :

// in rollup.config.js
{
    /** ... **/
    plugins: [
        resolve({
            mainFields: ["module", "main", "browser"],
        }),
        commonjs()
    ]
}

// in node_modules/yaml/browser/dist/index.js
export default {
  createNode: createNode,
  defaultOptions: defaultOptions,
  Document: Document,
  parse: parse,
  parseAllDocuments: parseAllDocuments,
  parseCST: parseCST,
  parseDocument: parseDocument,
  stringify: stringify
};

// in dist/main.js
var require$$0 = {
  createNode: createNode,
  defaultOptions: defaultOptions,
  Document: Document$2,
  parse: parse$1,
  parseAllDocuments: parseAllDocuments,
  parseCST: parse,
  parseDocument: parseDocument,
  stringify: stringify
};

var browser = require$$0.default; // ⚠️ require$$0.default is undefined !


// in src/main.js
import YAML from "yaml";
// YAML is undefined

YAML.stringify({ my: "input" }); // error

With a different node-resolve config, there is another bug (related to rollup/rollup#3054 ):

Circular dependency warning:

(!) Circular dependencies
node_modules/yaml/dist/schema/Collection.js -> node_modules/yaml/dist/schema/Pair.js -> node_modules/yaml/dist/schema/Collection.js
node_modules/yaml/dist/schema/Collection.js -> node_modules/yaml/dist/schema/Pair.js -> /Users/camille/git/bug-rollup-yaml/node_modules/yaml/dist/schema/Collection.js?commonjs-proxy -> node_modules/yaml/dist/schema/Collection.js
// in rollup.config.js
{
    /** ... **/
    plugins: [
        resolve({
            mainFields: ["module", "main"], // removed "browser"
        }),
        commonjs()
    ]
}

// in node_modules/yaml/dist/index.js
var _default = {
  createNode,
  defaultOptions,
  Document,
  parse,
  parseAllDocuments,
  parseCST: _parse.default,
  parseDocument,
  stringify
};
exports.default = _default;

// in dist/main.js

// Collection_1$1 is undefined
var _Collection = _interopRequireDefault(Collection_1$1);

// ...later ...
key instanceof _Collection.default; // throws, because _Collection.default is not an object

// ...

var _default = {
  createNode,
  defaultOptions,
  Document,
  parse,
  parseAllDocuments,
  parseCST: _parse.default,
  parseDocument,
  stringify
};
exports.default = _default; // ok


// in src/main.js
import YAML from "yaml";
// YAML is defined

return YAML.stringify(input); // Error, `Collection` isn't available in `Pair`

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published