question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

styles required with relative path leading to /src are not applied

See original GitHub issue

Do you want to request a feature or report a bug? bug, or configuration issue probably

What is the current behaviour? see header? has no class grafik

If the current behaviour is a bug, please provide the steps to reproduce.

  • preact create default my-project
  • copy src/components/header/style.css to src/
  • edit src/components/header/index.js to point to the new path ../../style.css
  • preact watch

What is the expected behaviour? header styles being applied, header background being violet e.g.

Please mention other relevant information.

the compiler finds the file, you can verify this by renaming it, but the styles are not applied to the dom (actually the styles are inserted, but the class name not).

Is this because of ../../? No, I verified this by adding one more folder in depth and then going back 2 folders relative and it works. It only fails once the path leads to src/, or further up from there: ../../test/style.css

Please paste the results of preact info here. System: OS: Windows 10 10.0.18362 CPU: (4) x64 Intel® Core™ i7-8559U CPU @ 2.70GHz Binaries: Node: 13.8.0 - C:\Program Files\nodejs\node.EXE npm: 6.13.6 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 44.18362.387.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rschristiancommented, Jun 18, 2020

CSS files imported from /components and /routes are the only ones treated as CSS modules. Importing from outside of those two means the CSS file isn’t a module. You can test this by changing <header class={style.header}> to <header class="header">. The purple header will be back.

Depending on what you want to do, you can customize the Webpack config using your preact.config.js (config to change can be found here) to work with any directories that you want.

This is only turned on for /components and /routes so you can use the other directories to import styles globally, such as index.js importing styles/index.css. I think it’s usually standard practice to keep your CSS file close to your component when using modules to cut down on the amount of searching you have to do, hence these defaults, but you should be free to change them if you wish.

0reactions
rschristiancommented, Jun 19, 2020

No, inline styling is just for writing CSS as JS. Obviously you can still import style sheets and use classes, but in a component, you only get standard CSS (in a JS naming convention).

If you added Less/Sass into the mix you’d have to somehow pre-process a component, which would get all sorts of complicated if not impossible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

img tag not working with relative path in src - Stack Overflow
So when I have url like http://127.0.0.1:7777/www/ then all my relative urls working but then I use it as http://127.0.0.1:7777/www (no "/" at...
Read more >
I cannot create relative path links - CSS - Codecademy Forums
Secondly and most annoyingly I'm having a major frustrating issue trying to create relative links either from files like images or to the...
Read more >
Can't use relative paths in url() in scss files #12797 - GitHub
I would like to be able to use the relative file path in the scss file. I know this is solved by using...
Read more >
Content Configuration - Tailwind CSS
Using relative paths. By default Tailwind resolves non-absolute content paths relative to the current working directory, not the tailwind.config.js file.
Read more >
escaping relative path require hell in Node.js - Corey Cleary
Although you'll then run into the same problem of needing to relative require files from your src , but hey you can do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found