Closed trusktr closed 7 years ago
So, if I change
jss.createStyleSheet({
'@global': {
'.grabbing': {
cursor: 'grabbing',
},
'div#app, div#imvu, div.mode-container': {
width: 100,
height: 100,
},
// hide the mode navbar for now.
'div#app': {
'& nav.global-nav.bar': {
display: 'none',
},
'& div.mode-container': {
paddingTop: 0,
},
},
},
}).attach()
to
jss.createStyleSheet({
foo: {
color: 'red',
},
}).attach()
then it works, no errors.
I have tried your code in the repl, it works
so it must be your versions or setup
@kof I don't know why, but I only get the error when I use @global
. So if I change it to the following I don't get any errors:
import jss from 'jss'
console.log('jss?', jss)
jss.createStyleSheet({
//'@global': {
'.grabbing': {
cursor: 'grabbing',
},
'div#app, div#imvu, div.mode-container': {
width: 100,
height: 100,
},
// hide the mode navbar for now.
'div#app': {
'& nav.global-nav.bar': {
display: 'none',
},
'& div.mode-container': {
paddingTop: 0,
},
},
//},
}).attach()
again, check your versions and your setup, your styles declaration with "@global" works on the repl.
Did you reproduce it in the repl with the same configuration as I have?
I just copied your styles and they work, which means its not a bug in jss.
please always try on the playground first before posting an issue http://cssinjs.org/repl The time you take for support is time I can't invest to actually fix bugs and features.
for configuration check out preset-default
What do I write in the repl? Would be nice if it started with an example.
return {
'@global': {
'.grabbing': {
cursor: 'grabbing',
},
'div#app, div#imvu, div.mode-container': {
width: 100,
height: 100,
},
// hide the mode navbar for now.
'div#app': {
'& nav.global-nav.bar': {
display: 'none',
},
'& div.mode-container': {
paddingTop: 0,
},
},
},
}
btw. it starts with an example actually
Thanks. It seems to be blank when I get there after clicking on your link.
Apparently repl doesn't work for me:
it fails to access localStorage, why?
whats special about your system?
Ah, I added an exception for cssinjs.github.io, and now it works.
@kof Ah, I think I see what the problem is: the jss-global
imports ContainerRule from jss, and it gets jss from var _jss = require('jss');
, which webpack sees using my alias, so Webpack gives the jss-global module my configured Jss instance instead of the CommonJS export from the jss
package.
jss-global
is the only plugin that imports from jss
, other plugins don't clash with my Webpack setting.
I can figure a solution now that I see what's happening.
hmm, maybe jss-global should access that object differently to avoid this sort of issues.
oh no, so you basically use a jss module namespace which is not the original jss, but your custom module???
Thats most probably a bad idea, using a custom name or local paths is what community does in this case.
oh no, so you basically use a jss module which is not the original jss, but your custom module???
Yep, I wanted to configure JSS for the whole app, and all app files were just doing
import jss from 'jss'
so the alias would make it an easy transition, and files can start using plugin features.
But I changed it so they all now do
import jss from 'app/configuredJss'
Thanks @trusktr, this thread has helped me fix one of my builds.
I had exactly the same error from a Rollup build. I was using a global jss module like you. rollup was replacing require('jss') with the global jss. However it was the build from this modules npm package (ie. not my own custom one). Basically, rollup grabs the default export if it exists and uses that (on global modules - I assume this is in the commonjs plugin). So, if you then try to use a named export that is not included in default you get an error. Hence my error:
Uncaught TypeError: _jss.RulesContainer is not a constructor
So, basically, I had to do a work-around to get rollup to use the named exports.
My logic for doing this was I have a few different build files and they all need access to jss. It made sense for them to use one global version of this, rather than bundling it with each.
I am not suggesting this is a sensible setup (I am probably going to refactor it all to avoid the hack and non-standard stuff). However, I had the same error, so, just in case someone else has a similar problem.
I'm getting an error with a stack trace like this:
I have
main.ts
:and
main.style.ts
:The environment is Webpack, and
jss
is aliased to./configuredJss.ts
(relative tomain.ts
), whereconfiguredJss.ts
contains:So anything that imports
jss
will cause the configuration to happen behind the scenes.Any idea what this error might be from?