BBob icon indicating copy to clipboard operation
BBob copied to clipboard

ES Module Bundling issue

Open Alteras1 opened this issue 3 years ago • 2 comments

Hello!

Looks like there's an issue with bundling the es modules. I'm trying to wrap it inside my own package with its own set of bbcode tags, and when I bundle it to esm or cjs (using rollup), I get quite a few "___ is not exported by ___" errors. Looks like it's because some import statements use the /lib directory.

i.e.

[!] Error: 'SLASH' is not exported by node_modules/BBob/packages/bbob-plugin-helper/lib/char.js, imported by node_modules/BBob/packages/bbob-parser/es/Token.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/BBob/packages/bbob-parser/es/Token.js (1:36)
1: import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from '@bbob/plugin-helper/lib/char';

This is my rollup.config.js, where src/index.ts imports @bbob/html, @bbob/preset, and @bbob/core, and applies its own set of tags.

import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import pkg from "./package.json";

export default [

  // CommonJS (for Node) and ES module (for bundlers) build.
  {
    input: "src/index.ts",
    output: [
      { file: pkg.main, format: "cjs", sourcemap: true },
      { file: pkg.module, format: "es", sourcemap: true },
    ],
    plugins: [resolve(), typescript({ tsconfig: "./tsconfig.json" })],
  },
];

Alteras1 avatar May 08 '22 22:05 Alteras1

Yep, I need to define "exports" field in package.json so all imports will be resolved properly. I may suggest to import from src folder or defined import aliases like @bbob/plugin-helper/lib/char to @bbob/plugin-helper/src/char

JiLiZART avatar May 09 '22 08:05 JiLiZART