Help: Chart.js in stylesheet

Hi, I just deployed Hugo site at Netlify. The index page here looks ok but the other pages like this does not seem to render properly. It works on my localhost.

One difference that catches my attention is this line. Why is there chart.js on the page that’s not rendered properly?
<link rel='stylesheet' type='text/css' media='all' href='https://d33wubrfki0l68.cloudfront.net/js/adc83b19e793491b1c6ea0fd8b46cd9f32e592fc/{$rootfolder}/assets/js/chart.js'/>

Here’s the deployment log

4:49:05 PM: Build started
4:49:05 PM: Fetching cached dependencies
4:49:06 PM: Starting to download cache of 32.5MB
4:49:06 PM: Finished downloading cache in 441.862835ms
4:49:07 PM: Preparing Git Reference refs/heads/netlify-hugo-version
4:49:10 PM: Found netlify.toml. Overriding site configuration
4:49:11 PM: Running build command: hugo
4:49:14 PM: v6.11.2 is already installed.
4:49:15 PM: Now using node v6.11.2 (npm v3.10.10)
4:49:15 PM: Using version v6.11.2 of node
4:49:15 PM: Using /opt/buildhome/.rvm/gems/ruby-2.4.0
4:49:15 PM: Set ruby from .ruby-version
4:49:15 PM: Started building sites ...
4:49:15 PM: Built site for language en:
0 of 1 draft rendered
4:49:15 PM: 0 future content
0 expired content
4:49:15 PM: 1 pages created
0 non-page files copied
4:49:16 PM: 0 paginator pages created
4:49:16 PM: 5 tags created
4:49:16 PM: 0 categories created
total in 19 ms
4:49:16 PM: Build complete: exit code: 0
4:49:16 PM: Cleaning up docker container
4:49:16 PM: Starting to deploy site from 'public'
4:49:16 PM: Deploying to CDN
4:49:16 PM: Starting deploy of directory /mnt/build-work/buildbot-855617200/repo/public
4:49:17 PM: Going to deploy the 0 required files
4:49:17 PM: Finished deploying directory /mnt/build-work/buildbot-855617200/repo/public
4:49:17 PM: Finished deploying 0 files in 639.391309ms
4:49:17 PM: Starting post processing
4:49:17 PM: Cleaning up the repository
4:49:17 PM: Post processing done
4:49:17 PM: Site is live
4:49:17 PM: Bundling and saving cache
4:49:22 PM: Finished uploading cache in 605.895732ms
4:49:23 PM: Finished processing build request in 17.596443088s

Thanks for your help!

1 Like

As this is most likely a problem in your template(s), it is hard to guess without seeing the … templates.

Thanks for looking, Erik (@bep) . Site repo is here

Update: Netlify asked me to disable asset optimization and it works… but I just wonder … as @bep said … something is wrong with my template… and to my suspicion…

I have 2 static folders, first, in /static/ where I store image for archetype posts /static/img and second in /themes/space/static where I store theme’s static files

I think it’s a couple things:

  1. You’re linking JavaScript as a stylesheet. This should be <script src="…, no?
  2. Also wondering what {$rootfolder} is since that’s not Hugo syntax. Assuming this is just an issue with Netlify’s asset optimization since they are using Cloudfront as part of their CDN for that particular asset, which is a conflict between mime type and type text/css.

Other than that, I don’t see anything wrong with the templating, since you are using your space theme and not overriding anything in the project-level layouts/partials folder…

Originally, the css codes are

<link href="css/stack-interface.css" rel="stylesheet" type="text/css" media="all">
        <link href="css/socicon.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/iconsmind.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/flickity.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/theme.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/custom.css" rel="stylesheet" type="text/css" media="all" />
        <link href="https://fonts.googleapis.com/css?family=Open+Sans:200,300,400,400i,500,600,700" rel="stylesheet">

Somehow, Netlify’s asset optimization changed it to <link rel=‘stylesheet’ type=‘text/css’ media=‘all’ href=‘https://d33wubrfki0l68.cloudfront.net/js/adc83b19e793491b1c6ea0fd8b46cd9f32e592fc/{$rootfolder}/assets/js/chart.js’/>

However, index.html page got it right. This is what confusing me the most …

Update! this is somewhat “enlightening” to me … the trick that works with Netlify’s asset optimization is to put my theme’s css,js,font,images under 1 folder called asset ! with this, Netlify is somehow understand.

Now my folder structure looks like this

.
├── README.md
├── archetypes
│   └── default.md
├── config.toml
├── content
│   └── projects
│       ├── 001.md
│       └── 002.md
├── layouts
├── netlify.toml
├── static
│   └── img
│       └── projects
│           └── 001
│               ├── featured.jpg
└── themes
    └── space
        ├── LICENSE.md
        ├── archetypes
        │   ├── default.md
        │   └── projects.md
        ├── layouts
        │   ├── 404.html
        │   ├── _default
        │   │   ├── baseof.html
        │   │   ├── list.html
        │   │   └── single.html
        │   ├── index.html
        │   ├── partials
        │   │   ├── footer
        │   │   ├── head
        │   │   ├── header
        │   │   ├── home
        │   │   └── projects
        │   └── projects
        │       ├── list.html
        │       └── single.html
        ├── static
        │   └── assets
        │       ├── css
        │       ├── fonts
        │       ├── img
        │       └── js
        └── theme.toml

As it turns out, the issue appears to be with the html <base> tag, which I’ve just learned causes confusion for Netlify’s postprocessing.

@vinamelody, Looking at the commit you made to move files into an assets folder, I see you also replaced the theme’s header template (which uses a <base> tag) with a new header that doesn’t. I suspect that’s the change that made everything work properly.

1 Like

oh really! that’s unexpected haha i looked at other templates and when I follow https://github.com/rdwatters/theme-starter-hugo , it worked…:smiley:

Thanks for sharing the info!

1 Like

Having exact same issue in a React project (no connection at all to Hugo), so I can confirm that this is a Netlify thing.

Just wanted to pile-on here since this is the only mention of this particular problem I’ve found so far

1 Like

Hi @brandonmp may be one of your project config has similar solution regarding the assets bundling too…

I’m having the same issue, using the Victor Hugo template.
This is my repo and this is my site. Homepage CSS worked but project page fails. (currently project pages work because Asset Optimization is off)


Turning off the Asset Optimization fixes the issue. But thats one of the main reasons I’m using Netlify instead of Github pages. I’m only beginning to learn about Gulp and Webpack so I’m suspicious on how the Victor Hugo template is setup. Am I missing something in my webpack.conf.js? (its located in the root of my repo)

1 Like

Any insight into this would be great because I’m facing the same issue with the same starter pack of Victor Hugo.

1 Like

@omar try to put your js and css under assets folder or if there’s any <base> tag, remove it

1 Like