The official "setup" example crashes with "preset is not a function"
Author: jameshfisherCreated Oct 22, 2021Updated Oct 17, 2023
Expected behavior: The official "setup" example works
Describe the bug: The official "setup" example crashes
Reproduction:
npm install jss jss-preset-defaultCreate test.js:
import jss from 'jss'
import preset from 'jss-preset-default'
jss.setup(preset())
// Create your style.
const style = {
myButton: {
color: 'green'
}
}
// Compile styles, apply plugins.
const sheet = jss.createStyleSheet(style)
// If you want to render on the client, insert it into DOM.
sheet.attach()
// If you want to render server-side, get the CSS text.
sheet.toString()$ node test.js
file:///Users/jim/dev/jameshfisher/test/test.js:4
jss.setup(preset())
^
TypeError: preset is not a function
at file:///Users/jim/dev/jameshfisher/test/test.js:4:11
at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)Weirdly, this works:
import jssModule from 'jss'
import presetModule from 'jss-preset-default'
const jss = jssModule.default
const preset = presetModule.default
jss.setup(preset())
// Create your style.
const style = {
myButton: {
color: 'green'
}
}
// Compile styles, apply plugins.
const sheet = jss.createStyleSheet(style)
// If you want to render server-side, get the CSS text.
console.log(sheet.toString())Versions (please complete the following information):
- jss: 10.8.1
- Browser [e.g. chrome, safari]:
- OS [e.g. Windows, macOS]: macOS
Source: cssinjs/jss