Issues following compilation with npm run prod

I am currently working on a small website using Laravel and Tailwind CSS on shared hosting. While I am able to use a command line tool on the host, I have encountered an issue. In my local environment, Tailwind works perfectly fine. However, after running 'npm run prod,' many of the Tailwind functionalities are missing and errors appear in the app.css and app.js files.

For example, the scaling effect on hover -

transform hover:scale-105 duration-200
does not work on the host server.

I attempted to import Tailwind with a CDN as a temporary fix, but I know this is not a sustainable solution.

I have been searching for an answer for several days without any success. What could be causing this issue? Any help would be greatly appreciated.

Answer №1

When working locally, you typically use npm run dev and for production, you use npm run prod. By default, Tailwind's development version does not remove unused styles. However, when running npm run prod, unused styles are purged for production usage.

According to the documentation, you need to configure the paths to your templates in the purge section of your tailwind.config.js.

module.exports = {
  purge: [
    './src/**/*.html',
    './src/**/*.vue',
    './src/**/*.jsx',
  ],
  // .. more ..

For more information, check out the docs.

This list should include any files in your project that reference any of your styles by name

If you fail to configure these paths, Tailwind won't know which classes you're using and will end up purging all styles it doesn't recognize, such as hover:scale-105.

Solution "dirty":
You can temporarily fix the issue by running npm run dev even in production, although this results in a bulky CSS build.

Solution "clean":
To permanently resolve the problem, ensure you correctly configure your paths so Tailwind can effectively recognize and purge unused styles.

You can also test this in your development environment by running npm run prod to observe the outcome.

Answer №2

Even after running npm run production, the app.css file still contains some warnings. Strangely, when I upload it to the host, those warnings turn into errors. Check out this screenshot for reference:

https://i.sstatic.net/E9TgY.png

Interestingly, everything works smoothly when I use the file after running npm run dev. It's possible that there are clashes between Tailwind classes causing these issues. I will investigate further and provide a solution soon.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing CSS styles based on the count of elements

Within my react js project There is a particular block that may contain either one or two elements, depending on the runtime conditions. For instance: Scenario 1: (two groups are present) <div class='menu-list'> <div class='g ...

Smartphone screen cluttered with overlapping paragraphs

I am encountering a paragraph overlap issue while using a bootstrap template, specifically on smartphones like iPhone 6 with Safari. Interestingly, the problem does not appear when testing on a browser by shrinking the window size to the minimum. On the ph ...

Encountering the "ERR_MODULE_NOT_FOUND" error when running "yo code" in VSCode is causing some frustration

While attempting to create a custom extension in vscode, I am encountering an issue every time I execute the command yo code (as per the instructions in the vscode tutorial). The error message that keeps appearing is: Error [ERR_MODULE_NOT_FOUND]: Cannot f ...

Using Laravel Mix alongside node-notifier led to a SyntaxError where an unexpected token 'export' was encountered

I attempted to execute npm run production command but encountered an error Node Version: 14.15.4 Npm Version: 6.14.10 > cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/s ...

Storing github releases on internal network for enhanced security

Our team has a few NPM packages that require binary files to be present during their installation process. For example, when installing node-sass, the package needs a binary file that can be found on the node-sass releases page. We are currently working i ...

Struggling with smoothly transitioning an image into view using CSS and JavaScript

I'm currently experimenting with creating a cool effect on my website where an image fades in and moves up as the user scrolls it into view. I've included the code I have so far below, but unfortunately, I keep getting a 404 error when trying to ...

Tips for resizing the dimensions of two div elements to fit the screen dimensions

Take a look at this template. It's interesting how the left content div and right sidebar divs adjust themselves based on the browser window size, zoom level, or viewing device such as a mobile phone. When viewed on a mobile, only the content div is d ...

What is the solution to this issue? How can I break the grid row in Bootstrap 4? Which specific Bootstrap classes should I apply for this task?

Test Links. Utilizing Bootstrap classes, adjust the div element with the ID "links" to display differently based on screen resolutions. On extra small screens (<576px), each link and ad should occupy one whole row. It will have this appearance: https:// ...

Troublesome alignment with bootstrap grid system

I require some assistance with the following: Specifically, I need help regarding the structure shown below: <div class="row"><div class="col-md-4"> <a class="individ" href="index.php?p=x" style="margin:5px 5px;"> ...

Troubleshooting problem with presenting real-time data in a Bootstrap Carousel using PHP

Currently, I am in the process of developing a dynamic events calendar to showcase on a website homepage. The information displayed on this calendar is retrieved from a database using PHP. Additionally, I have implemented the Bootstrap framework (version 4 ...

Having trouble with running npm install after updating node js?

Images displaying error messages First Image Second Image Third Image Version of Node.js ...

As you scroll, a box blocks off half of the screen

Hey everyone, I could really use your assistance! I'm working on developing a javascript code and here is the idea - if anyone can contribute to it. It's like a social media platform where users enter the site and the is_user_logged_in parameter ...

Trouble with Divs and Element Placement

I am struggling to recreate this layout example. I attempted to make it align correctly, but I am having trouble looping the comment box under the review score. Can someone provide an example or guide me on how to achieve this design? Example image: http ...

having trouble with starting the React script

Working on a React project in the Intellij IDE, I encountered an issue when attempting to start it with npm. The error message pointed to an issue with the start script in the package.json. I've followed common advice such as reinstalling node.js and ...

EBUSY: Unable to access resource due to being busy or locked, unable to retrieve information from 'C:hiberfil.sys'

I am running into an issue while attempting to publish an npm package. The error message I keep receiving is causing me some trouble. Does anyone have any suggestions on how I can resolve this? Your help would be greatly appreciated! Thank you in advance ...

Exploring jQuery Animation Effects: Enhancing Your Web Experience with Zoom In and Zoom Out

Is there a way to animate a logo using jQuery automatically upon page load? I want the image to zoom out, then zoom in and change to a different image. Can someone please assist me with this task? Below is the code snippet that I have: $(document).ready ...

implement an angular directive to apply a CSS element

I am utilizing AngularJS and ng-repeat to populate a dynamic list of studies. This list has the capability to toggle into child elements of each item, creating an accordion-style toggle list that can go up to three levels deep for each list item. I am curr ...

Installing packages globally and locally with npm leads to the installation of varying components

There seems to be a discrepancy in the results I get when installing a package with --global compared to a local installation. For instance I recently installed https://github.com/sverweij/dependency-cruiser $ npm install --save-dev dependency-cruiser W ...

Overlay one image onto another using Jimp

I am currently making modifications to images in my server-side node.js application. I have successfully added text over my image, but now I want to place a green rectangle at the top left corner of the image. Here is the method I attempted: Jimp.read(`bo ...

Grammarly is seamlessly inserting padding into my body element

After setting up my website on GitHub, I ran into an issue where the Grammarly Chrome extension was automatically adding a padding-top attribute to the body tag. <body data-new-gr-c-s-check-loaded="14.1028.0" data-gr-ext-installed="" ...