What could be causing an unidentified term to be included in the Vue SCSS compilation process

In my Vue application with TypeScript, I encountered an error during compilation that reads as follows:

Failed to compile.

./src/style.scss (C:/../node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!C:/.../node_modules/vue-loader/lib/loaders/stylePostLoader.js!C:/.../node_modules/postcss-loader/src??ref--8-oneOf-1-2!./src/style.scss)
Module build failed (from C:/.../node_modules/postcss-loader/src/index.js):
SyntaxError

(10:14) Unknown word

   8 | 
   9 |   @if $point == big {
> 10 |     @media #{$bp-big} {
     |              ^
  11 |       @content;
  12 |     }

I'm confused as to why SCSS is not recognizing variables. What does the "Unknown word" message mean and how could I resolve this issue?

This snippet shows how my app.vue looks like:

<template>
  ...
</template>

<style lang="scss">
@import url('./style.scss');
</style>

Here's the mixin definition inside style.scss:

@mixin bp($point) {
  $bp-xsmall: '(min-width: 320px)';
  $bp-teeny: '(min-width: 480px)';
  $bp-tiny: '(min-width: 600px)';
  $bp-small: '(min-width: 650px)';
  $bp-medium: '(min-width: 800px)';
  $bp-big: '(min-width: 1000px)';

  @if $point == big {
    @media #{$bp-big} {
      @content;
    }
  } @else if $point == medium {
    @media #{$bp-medium} {
      @content;
    }
  } @else if $point == small {
    @media #{$bp-small} {
      @content;
    }
  } @else if $point == tiny {
    @media #{$bp-tiny} {
      @content;
    }
  } @else if $point == teeny {
    @media #{$bp-teeny} {
      @content;
    }
  } @else if $point == xsmall {
    @media #{$bp-xsmall} {
      @content;
    }
  }
}

Answer №1

After making extensive modifications to the <style> section of my file, I encountered a persistent error labeled as "Unknown word." Interestingly, this error persisted even though no changes were reflected in the git diff. Strangely enough, removing the <style> section entirely did not resolve the issue.

Upon further investigation, it was discovered that the problem stemmed from poorly compiled SCSS files.

Resolution

For users of Nuxt, executing the following command solved the issue:

$ npx nuxi cleanup

Alternatively, for those not using Nuxt, the above command effectively removes the specified directories:

.nuxt
.output
node_modules/.vite
node_modules/.cache

Subsequently running the application resulted in smooth operation thereafter.

This solution proved consistently effective upon repeated testing of the same issue.

Answer №2

Have you included the sass-loader and vue-style-loader in your build process?

Ensure they are added to your modules section of the webpack.config.js

{
    test: /\.scss$/,
    use: [
        'vue-style-loader',
        'css-loader',
        'sass-loader',
        'postcss-loader',
    ],
},

If there are issues, it might be related to your webpack configuration rather than TypeScript integration. Can you share your webpack.config file for further analysis?

Instead of importing styles within the <style> tag in App.vue, consider importing them in your main.js like so:

import './styles.scss';

But remember, the correct loaders must still be set up appropriately.

Answer №3

By updating the code from @import url('./style.scss'); to @import './style.scss';, you can resolve the error at hand.

When working on a Vue.js project, choosing to use @import './style.scss'; over @import url('./style.scss'); allows for the utilization of a more contemporary SCSS import syntax.

The reason behind this modification's effectiveness:

Webpack and SCSS Loader Integration: Vue.js projects typically leverage Webpack in conjunction with a SCSS loader to manage SCSS files. The SCSS loader is well-equipped to handle SCSS imports seamlessly.

Efficient File Resolution: In current SCSS configurations, omitting url() when importing SCSS files proves advantageous as the SCSS loader can autonomously resolve and incorporate the file accurately.

Enhanced Simplicity and Uniformity: Opting for @import './style.scss'; stands out for its simplicity and synchronization with contemporary SCSS methodologies. This results in maintaining a consistent codebase, facilitating streamlined maintenance procedures and diminishing error susceptibility.

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

The icon for the weather on openweathermap is currently not displaying

Take a look at what my webpage looks like: http://prntscr.com/dg6dmm and also check out my codepen link: http://codepen.io/johnthorlby/pen/dOmaEr I am trying to extract the weather icon from the api call and display that icon (e.g. "02n") on the page base ...

Is it possible to alter the state just by clicking on the text?

I am currently facing a challenge in creating a select option for switching between notify and not notify status while using the regular text format preferred by my customer. The default value is set to notify, and upon clicking on the text it should chang ...

Click on the text within a paragraph element

Is there a way to retrieve the selected text or its position within a paragraph (<p>)? I'm displaying a text sentence by sentence using a Vue.js loop of paragraphs. <p class="mreadonly text-left mark-context" v-for="line in ...

Create a Bootstrap layout with three columns and three rows, where the third column has a height

I am trying to achieve a specific layout using the col-lg-4 class. My main goal is to make the third column span across all three rows without creating excessive white space between them. The current layout looks like this: Is it possible to do this in B ...

What is the best way to transfer variables between two Vue files?

How can I transfer a variable between two Vue files? Hello, in my SendCode.vue file, I have a variable named NewEmail that I would like to use in another file called changePass.vue. Is there any way to do this? Can someone offer assistance? Thank you</p ...

Changing Bootstrap variables within a React application: A step-by-step guide

I've been working with facebook's create-react-app and I successfully added SASS to my project. Now, I'm trying to incorporate Bootstrap and customize the theme but running into some issues. Here's what my setup looks like: package.jso ...

Solving the issue of 'b-modal' not appearing in a Vue.js custom component

Software Used: Vue.js Bootstrap-Vue () Issue: My aim is to show a popup when a row is clicked within a bootstrap grid. Once the modal is closed, I want it to disappear and the selected item to be removed. To tackle this problem, I have developed a custo ...

There seems to be an issue with the accurate calculation of the screen width while utilizing the scrollbar-gutter

Please take note: The scrollbar-gutter: stable; property is not compatible with Safari. Additionally, the issue seems to be specific to Chrome and works fine in Firefox. I have observed some unusual behavior when attempting to position elements fixed to t ...

Creating a stylish menu with CSS and Bootstrap featuring two beautifully designed rows

Looking to design a header for a webpage that features a logo on the left side in the center, along with two rows of menu items positioned on the right using CSS and Bootstrap classes. Below is an example layout: ---------------------------------------- ...

Retrieving Data from Vuetify Component within vue 3

Currently, I am in the process of creating my own wrapper for Vuetify components to eliminate the need to repeatedly define the same props in each component. For example, I aim to develop a custom TextField with defaultProps while still being able to accep ...

Best practices for referencing attributes created with the data method in a Vue component

In my application, there is a section that displays a list of users along with a search box to filter names. The user information is fetched from a database and stored in app.users. I have created a component named 'user' to show the details of e ...

What is the most efficient way to enable seamless communication between sibling components in Vue.js 2?

Just starting out with Vue.js 2 and I'm really enjoying it so far despite being new to it. Currently using the latest version. I've begun working on my first larger application and ran into a scenario right off the bat where I have a main app co ...

Adjust the dimensions of the initial cell

I need to adjust the size of the initial "generated" cell in a grid. The grid is not present in the HTML markup until JavaScript prints RSS information on it, making it difficult to target specific rows or cells directly. Note: The first element is hidden ...

Modifying a Nested Component with react-icons

As I work on creating a rating component that utilizes react-icons to display icons, I have encountered an interesting challenge. Currently, I am using the FaStarhalf icon which represents a pre-filled half star that can be flipped to give the appearance o ...

Toggle the visibility of a div based on the id found in JSON data

I am looking to implement a JavaScript snippet in my code that will show or hide a div based on the category ID returned by my JSON data. <div id="community-members-member-content-categories-container"> <div class="commun ...

Align images of varying sizes vertically within div containers, even when the image is larger than the div itself

I'm facing a challenge when it comes to aligning images vertically inside divs. The problem arises due to the following conditions: The images will have varying and unknown sizes. These images are larger than the divs they are contained in, requiri ...

Leverage the utility API provided by Bootstrap in my SCSS stylesheet

The Bootstrap documentation provides instructions on how to implement negative margins, but these are typically used when customizing Bootstrap. Even though I am using Bootstrap from a CDN, I still need access to those specific classes (e.g., mt-n1). I wo ...

How can you adjust the div orientation for small screens using Bootstrap?

I've been working with Bootstrap and I'm facing an issue with the orientation of a div on small screens. On medium screens, I have two columns set to 6, 6 which should stack on top of each other on smaller screens. Here's how I want it to lo ...

Determine when the scrollbar of a DIV has reached the bottom using Vue.js

Just starting out with Vuejs and I could use some guidance. Can anyone please advise on how to trigger a message when a div in Datatable vuejs reaches the bottom of its page? Any help would be greatly appreciated. https://i.sstatic.net/jKfRT.jpg https://i ...

Vue-bootstrap spinbutton form with customizable parameters

I am in need of a custom formatter function for the b-form-spinbutton component that depends on my data. I want to pass an extra argument to the :formatter-fn property in the code snippet below, but it is not working as expected. <b-form-spinbutton :for ...