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

[7.0 alpha] webpack stylus loader doesn't work anymore #19049

Open
EvHaus opened this issue Aug 29, 2022 · 17 comments · Fixed by #22486
Open

[7.0 alpha] webpack stylus loader doesn't work anymore #19049

EvHaus opened this issue Aug 29, 2022 · 17 comments · Fixed by #22486

Comments

@EvHaus
Copy link
Contributor

EvHaus commented Aug 29, 2022

Describe the bug
After upgrading from 6.5.10 to 7.0.0-alpha.26 I'm running into an issue with stylus-loader. When starting Storybook, I get this failure:

WARN Force closed manager build
/Users/me/myproject/node_modules/webpack/lib/NormalModule.js:758
				const error = new ModuleBuildError(err, {
				              ^

ModuleBuildError: Module build failed (from ../node_modules/css-loader/dist/cjs.js):
CssSyntaxError

(1:1) /Users/me/myproject/client/webapp/src/stylus/main-webapp.styl Unknown word

> 1 | [Root]
    | ^

    at null.processResult (/Users/me/myproject/node_modules/webpack/lib/NormalModule.js:758:19)
    at null.<anonymous> (/Users/me/myproject/node_modules/webpack/lib/NormalModule.js:860:5)
    at null.<anonymous> (/Users/me/myproject/node_modules/loader-runner/lib/LoaderRunner.js:399:11)
    at null.<anonymous> (/Users/me/myproject/node_modules/loader-runner/lib/LoaderRunner.js:251:18)
    at null.context.callback (/Users/me/myproject/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at Object.loader (/Users/me/myproject/node_modules/css-loader/dist/index.js:143:5)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

The loader that causes this issue is:

{
    test: /\.styl$/,
    use: ['style-loader', 'css-loader', 'stylus-loader'],
}

This problem doesn't happen with the same configuration on Storybook 6.5.10.

To Reproduce

WARN Force closed manager build
/Users/evhaus/Git/storybook-stylus-bug/node_modules/webpack/lib/NormalModule.js:758
				const error = new ModuleBuildError(err, {
				              ^

ModuleBuildError: Module build failed (from ./node_modules/css-loader/dist/cjs.js):
CssSyntaxError

(1:1) /Users/evhaus/Git/storybook-stylus-bug/stories/button.styl Unknown word

> 1 | [Root]
    | ^

    at null.processResult (/Users/evhaus/Git/storybook-stylus-bug/node_modules/webpack/lib/NormalModule.js:758:19)
    at null.<anonymous> (/Users/evhaus/Git/storybook-stylus-bug/node_modules/webpack/lib/NormalModule.js:860:5)
    at null.<anonymous> (/Users/evhaus/Git/storybook-stylus-bug/node_modules/loader-runner/lib/LoaderRunner.js:400:11)
    at null.<anonymous> (/Users/evhaus/Git/storybook-stylus-bug/node_modules/loader-runner/lib/LoaderRunner.js:252:18)
    at null.context.callback (/Users/evhaus/Git/storybook-stylus-bug/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at Object.loader (/Users/evhaus/Git/storybook-stylus-bug/node_modules/css-loader/dist/index.js:143:5)

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

System

  System:
    OS: macOS 12.5.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.14.1 - ~/.nvm/versions/node/v16.14.1/bin/node
    Yarn: 3.2.3 - /opt/homebrew/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.1/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Firefox: 103.0.2
    Safari: 15.6.1
  npmPackages:
    @storybook/addon-actions: ^7.0.0-alpha.26 => 7.0.0-alpha.26 
    @storybook/addon-docs: ^7.0.0-alpha.26 => 7.0.0-alpha.26 
    @storybook/addon-essentials: ^7.0.0-alpha.26 => 7.0.0-alpha.26 
    @storybook/addon-interactions: ^7.0.0-alpha.26 => 7.0.0-alpha.26 
    @storybook/addon-links: ^7.0.0-alpha.26 => 7.0.0-alpha.26 
    @storybook/react-webpack5: ^7.0.0-alpha.26 => 7.0.0-alpha.26 
    @storybook/testing-library: ^0.0.14-next.0 => 0.0.14-next.0 

Additional context

N/A

@EvHaus
Copy link
Contributor Author

EvHaus commented Mar 14, 2023

Just confirming this is still an issue in 7.0.0-rc.3. I haven't been able to find any workaround yet.

@shilman
Copy link
Member

shilman commented Mar 28, 2023

One of the main differences between 6.5 and 7.0 is that 6.5 is webpack4 by default and 7.0 is webpack5 only. Is the version of stylus-loader you're using webpack5 compatible?

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack4-support-discontinued

@EvHaus
Copy link
Contributor Author

EvHaus commented Mar 28, 2023

Yes, it's webpack5-compatible. I'm using the latest version and my main app build is using webpack 5.

@ramirozap
Copy link

I'm having the same issue on 7.0.0-rc.8, even tried a different loader https://github.com/slightlyfaulty/stylus-native-loader and gives the same error.
The main app is running fine with webpack 5 and the same loader configuration as storybook

@AumyF
Copy link

AumyF commented Apr 14, 2023

I created a reproduction repository using Storybook 7.0.2. https://github.com/AumyF/repro-storybook7-stylus

[Root] is the string representation of Stylus's AST root node (src).

The implementation of stylus compiler depends on AST node constructors' name such as Root, which is renamed like Root2 during storybook dev or build. https://github.com/stylus/stylus/blob/73708f31a28bbf289896036c12d0e500bda3605b/lib/visitor/index.js#L26-L30

When the compiler couldn't find a method corresponding to an AST node it just returns the AST object instead of compiled CSS source string. It's passed to the latter loader (typically css-loader) and it reports a syntax error.

It was not clear why the variable names were rewritten only on Storybook 7.

@MrSunshyne
Copy link

Can confirm this is also happening when the builder is Vite. Unknown word error.
Switching to another preprocessor doesn't cause the error, but stylus + SB7 + Vite simply breaks

@jamieathans
Copy link

jamieathans commented May 1, 2023

Issue still exists as of Storybook 7.0.7 - can anyone think of any workarounds (using webpack 5)?

@youngboy
Copy link
Contributor

youngboy commented May 9, 2023

I think I may found the issue causing it.

this is where to set keepNames of esbuild conf

https://github.com/storybookjs/storybook/blob/next/code/lib/core-common/src/utils/interpret-require.ts#L11-L23

@AlekseyPn
Copy link

AlekseyPn commented Jun 1, 2023

Hi. Is there any updates about stylus + vue + vite build for this issue? I have troubles with vue-vite build and stylus styles
version 7.0.13 doesn't work with stylus

@AlekseyPn
Copy link

Hi. Is there any updates about stylus + vue + vite build for this issue? I have troubles with vue-vite build and stylus styles version 7.0.13 doesn't work with stylus

I have downgraded storybook version to 6.5.16 and it solved my problem.

@EvHaus
Copy link
Contributor Author

EvHaus commented Jun 22, 2023

Just tried 7.0.23 which has the PR that should fix the problem but I'm still getting the error. Is there some setting or flag I need to enable first?

@ndelangen
Copy link
Member

@youngboy if the PR doesn't address this issue, we should probably revert the PR.?

@FRobaglia
Copy link

FRobaglia commented Jun 23, 2023

Hi, the PR resolves the issue, but it looks like it's not present in the code when using v7.0.23

(see node_modules/@storybook/core-common/dist/index.js, no occurences of keepNames is found. Adding it manually does fix the problem)

@ndelangen
Copy link
Member

Will be part of #23185

@EvHaus
Copy link
Contributor Author

EvHaus commented Jun 27, 2023

Unfortunately the issue is still happening for me with v7.0.24. I've updated the repro repo here: https://github.com/EvHaus/storybook-7-stylus-bug

@ndelangen ndelangen reopened this Jun 27, 2023
@youngboy
Copy link
Contributor

youngboy commented Jun 28, 2023

Unfortunately the issue is still happening for me with v7.0.24. I've updated the repro repo here: https://github.com/EvHaus/storybook-7-stylus-bug

seems there are two issues here

  1. keepNames still not present in v7.0.24
  2. in this repo set keepNames: true throw ReferenceError: __name is not defined error (looks like conflict with Webpack css-loader); switch to @storybook/react-vite framework is working

Maybe by default storybook should turn keepNames off, and expose a configuration option to turn it on, more info see vitejs/vite#2376 (comment)

@ryota-ka
Copy link

I've retried to build an app w/ Stylus on Storybook v7.6.4, and it all worked.

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

Successfully merging a pull request may close this issue.