You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way Vite passes custom preprocessor options to stylus leads to this bug (I think this is also due to a bug in stylus, but a workaround can be easily done in Vite to avoid this bug).
This causes the final ref to have its imports option completely overridden by our custom ones. Whereas, out of the box, this ref has already an imports option with the internal stylus file node_modules/stylus/lib/functions/index.styl which is required for correct compilation.
Reproduction
Having install stylus node module, this code will show the error:
conststylus=require('stylus')constsource=`$easing := cubic-bezier(0.4, 0.0, 0.2, 1)`constoptions={imports: ['path/to/my/variables.styl']}constref=stylus(source)// Here if you console.log(ref), you will see that this ref has// an `import` option with the required internal file I mentionedObject.keys(options).forEach((key)=>ref.set(key,options[key]))// Failsconstresult=ref.render()
Workaround
This works properly:
conststylus=require('stylus')constsource=`$easing := cubic-bezier(0.4, 0.0, 0.2, 1)`constoptions={imports: ['path/to/my/variables.styl']}// Pass options directly here, they will be properly merged with internal onesconstref=stylus(source,options)// Compiles properlyconstresult=ref.render()
I'll try to do the PR for that fix/workaround, while notifying stylus for the bug.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Provide a description in this issue that describes the bug.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
Describe the bug
Related to this answer #832 (comment)
I use:
to globally import a stylus file for the compilation.
In my project I have another file containing
$easing := cubic-bezier(0.4, 0.0, 0.2, 1)
which should be compiled normally. However, I get the error:The way Vite passes custom preprocessor options to stylus leads to this bug (I think this is also due to a bug in stylus, but a workaround can be easily done in Vite to avoid this bug).
Indeed, Vite passes these options after having booted stylus on the source, see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/css.ts#L1110
This causes the final
ref
to have itsimports
option completely overridden by our custom ones. Whereas, out of the box, thisref
has already animports
option with the internal stylus filenode_modules/stylus/lib/functions/index.styl
which is required for correct compilation.Reproduction
Having install
stylus
node module, this code will show the error:Workaround
This works properly:
I'll try to do the PR for that fix/workaround, while notifying stylus for the bug.
System Info
Used package manager: yarn
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: