JiLiZART / BBob

⚡️Blazing fast js bbcode parser, that transforms and parses bbcode to AST and transform it to HTML, React, Vue with plugin support in pure javascript, no dependencies
https://codepen.io/JiLiZART/full/vzMvpd
MIT License
163 stars 19 forks source link

ES Module Bundling issue #135

Open Alteras1 opened 2 years ago

Alteras1 commented 2 years ago

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" })],
  },
];
JiLiZART commented 2 years ago

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