Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esbuild bundling breaks Stylus compiler due to dependency to Function.prototype.name #2787

Open
AumyF opened this issue Apr 17, 2023 · 1 comment

Comments

@AumyF
Copy link

AumyF commented Apr 17, 2023

To reproduce:

Clone https://github.com/AumyF/repro-stylus-esbuild and node dist.js. Though this file is compiled from main.js which compiles a stylus source to css string, it will prints stylus AST object.

Current behavior:

stylus(styl).render() returns a Stylus AST object instead of a compiled CSS string. Because of this stylus-loader does not work on Storybook 7 which uses esbuild internally (storybookjs/storybook#19049).

Causes:

var Root = module.exports = function Root(){

Because esbuild rewrites this line like var Root = module.exports = function Root2(){, Root.name changes to 'Root2' and implementation depending to such .name property break.

Visitor.prototype.visit = function(node, fn){
var method = 'visit' + node.constructor.name;
if (this[method]) return this[method](node);
return node;
};

Specifying --keep-names is a workaround for this issue, but Storybook does not provide to set option of esbuild.

Expected behavior:

stylus works fine after bundling.

Also, we should do something about returning as AST object on error.

Environment information:

  • stylus version: 0.59.0
  • nodejs version: 18.15.0
  • esbuild version: 0.17.17
@nicolas-kffein
Copy link

nicolas-kffein commented May 4, 2023

Did you find a way to recompile this correctly ?

  • I'd like to patch this while storybook team fix this issue)
  • I have no cue on how to rebuild storybook...

I've tried to add this within vite config WITHOUT success
(inside defineConfig)

  esbuild: {
    minifyIdentifiers: false,
    keepNames: true,
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants