rhand's avatar
Level 6

Laravel Mix to Vite upgrade issues on Laravel 9 + Vue2

Used Laravel Shift Vite shift from Laravel Mix to Latest Vue Vite and trying to patch things up in Laravel 9 Vue 2 application but got stuck

npm run dev

> dev
> vite


  VITE v3.2.10  ready in 461 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
✘ [ERROR] [plugin vite:dep-scan] Cannot read properties of undefined (reading 'length')

    node_modules/esbuild/lib/main.js:1336:21:
      1336 │         let result = await callback({
           ╵                      ^

    at matches (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:140:35)
    at file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:203:58
    at Array.find (<anonymous>)
    at Context.resolveId (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:203:42)
    at Object.resolveId (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40539:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async resolve (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40763:26)
    at async file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40937:34
    at async requestCallbacks.on-resolve (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:1336:22)
    at async handleRequest (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:706:13)

  This error came from the "onResolve" callback registered here:

    node_modules/esbuild/lib/main.js:1260:20:
      1260 │       let promise = setup({
           ╵                     ^

    at setup (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40927:19)
    at handlePlugins (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:1260:21)
    at buildOrServeImpl (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:951:5)
    at Object.buildOrServe (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:759:5)
    at /Users/user/code/site.com/node_modules/esbuild/lib/main.js:2096:17
    at new Promise (<anonymous>)
    at Object.build (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:2095:14)
    at build (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:1942:51)
    at file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40711:46

  The plugin "vite:dep-scan" was triggered by this import

    resources/js/published-vendor.js:11:21:
      11 │     import Vuex from 'vuex'
         ╵                      ~~~~~~

In that file it mentioned resources/js/published-vendor.js part related to VueX is:

// Extend the String prototype with a cleanup() function that only keeps ascii characters and replaces others with '-'
    String.prototype.cleanup = function() {
        return this.toLowerCase().replace(/[^a-zA-Z0-9]+/g, "-");
    };

    // Extend the string prototype with a capitalizeFirstLetter function
    String.prototype.capitalizeFirstLetter = function() {
        return this.charAt(0).toUpperCase() + this.slice(1);
    };

    import Vuex from 'vuex'
    import Vue from 'vue'
    window.Vue = Vue
    import axios from 'axios';
    window.axios = axios;
...
window.Vue.use(Vuex)

What is wrong with this import? Is it not ES5? I think it is? Do I need to add .vue? Tried and did not help. Is it due to addition of VueX to window as I did in the end?

0 likes
12 replies
LaryAI's avatar
Level 58

The error you're encountering is related to the Vite dependency scanning process, which is having trouble resolving the vuex import. This issue can arise due to several reasons, including the way dependencies are imported or how Vite is configured to handle them.

Here are some steps to troubleshoot and resolve the issue:

  1. Ensure Compatibility: Make sure that the versions of Vue, Vuex, and Vite you are using are compatible with each other. Vue 2 and Vuex should work fine with Vite, but it's always good to double-check the versions.

  2. Update Vite Configuration: Sometimes, Vite needs a bit of help to properly resolve certain dependencies. You can update your vite.config.js to include the necessary configurations.

  3. Check for CommonJS Modules: Vite handles ES modules by default, but some packages might still be in CommonJS format. You can use the @vitejs/plugin-legacy plugin to handle these cases.

  4. Correct Import Statements: Ensure that your import statements are correct and that there are no typos or issues with the paths.

Here is a step-by-step solution:

Step 1: Update vite.config.js

Ensure your vite.config.js is properly configured to handle Vue 2 and Vuex. You might need to add the @vitejs/plugin-vue2 plugin.

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue2';

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      'vue': 'vue/dist/vue.esm.js',
    },
  },
});

Step 2: Install Necessary Plugins

Make sure you have the necessary plugins installed:

npm install @vitejs/plugin-vue2

Step 3: Update Your JavaScript File

Ensure your resources/js/published-vendor.js file is correctly importing and using Vue and Vuex:

import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';

window.Vue = Vue;
window.axios = axios;

Vue.use(Vuex);

// Extend the String prototype with a cleanup() function that only keeps ascii characters and replaces others with '-'
String.prototype.cleanup = function() {
    return this.toLowerCase().replace(/[^a-zA-Z0-9]+/g, "-");
};

// Extend the string prototype with a capitalizeFirstLetter function
String.prototype.capitalizeFirstLetter = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Step 4: Run Vite

After making these changes, try running Vite again:

npm run dev

Additional Tips

  • Check for Typos: Ensure there are no typos in your import statements.
  • Clear Cache: Sometimes, clearing the npm cache can help resolve unexpected issues:
    npm cache clean --force
    

By following these steps, you should be able to resolve the issue with Vite not being able to read properties of undefined during the dependency scan. If the problem persists, consider checking the Vite and Vue documentation for any additional configuration that might be required.

1 like
rhand's avatar
Level 6

I added Vue common as alias as I was using that before in Laravel Mix:

...
 alias: [
        {
            'vue$': 'vue/dist/vue.common.js',
        },
        {
            // this is required for the SCSS modules
            find: /^~(.*)$/,
            replacement: '',
        },
        {
            '@': path.resolve(__dirname, './resources/assets/vendor/MediaManager/js')
        },
        {
            '@': path.resolve(__dirname, './resources/js')
        },
        {
            '@': path.resolve(__dirname, './resources/js/store')
        },
        {
            '@': path.resolve(__dirname, './resources/js/store/preview')
        },
        {
            '@': path.resolve(__dirname, './resources/js/store/published')
        },
        
    ],
...

But I still get similar errors like

npm run dev

> dev
> vite

Port 5173 is in use, trying another one...

  VITE v3.2.10  ready in 468 ms

  ➜  Local:   http://localhost:5174/
  ➜  Network: use --host to expose
✘ [ERROR] [plugin vite:dep-scan] Cannot read properties of undefined (reading 'length')

    node_modules/esbuild/lib/main.js:1336:21:
      1336 │         let result = await callback({
           ╵                      ^

    at matches (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:140:35)
    at file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:203:58
    at Array.find (<anonymous>)
    at Context.resolveId (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:203:42)
    at Object.resolveId (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40539:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async resolve (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40763:26)
    at async file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40992:34
    at async requestCallbacks.on-resolve (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:1336:22)
    at async handleRequest (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:706:13)

  This error came from the "onResolve" callback registered here:

    node_modules/esbuild/lib/main.js:1260:20:
      1260 │       let promise = setup({
           ╵                     ^

    at setup (file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40988:19)
    at handlePlugins (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:1260:21)
    at buildOrServeImpl (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:951:5)
    at Object.buildOrServe (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:759:5)
    at /Users/user/code/site.com/node_modules/esbuild/lib/main.js:2096:17
    at new Promise (<anonymous>)
    at Object.build (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:2095:14)
    at build (/Users/user/code/site.com/node_modules/esbuild/lib/main.js:1942:51)
    at file:///Users/user/code/site.com/node_modules/vite/dist/node/chunks/dep-372dab03.js:40711:46

  The plugin "vite:dep-scan" was triggered by this import

    resources/js/preview.js:1:18:
      1 │ import store from './store/preview'
        ╵                   ~~~~~~~~~~~~~~~~~
...

So although it could be an issue with some packages still working with Common JS this alias does not work. So either I am doing that wrong too or I need to update more packages. But the Vite deep scan dose not explain too much. The preview.js error on line one refers to

import store from './store/preview'

which loads a VueX store file with data:

import Vue from 'vue'
import Vuex from 'vuex'

import previewModule from './modules/preview-module'

Vue.use(Vuex)

const store = new Vuex.Store({
  strict: false,
  modules: {
    preview: previewModule,
  },
})

export default store

So what is wrong there? Path seems correct...

rhand's avatar
Level 6

Upgrade VueX, Vue Compiler and that seems to improve matters. That and some improved imports . Just dealing with some remaining issues

transforming (136) resources/js/components/preview/ExtendModule.vueWarning: 34 repetitive deprecation warnings omitted.

transforming (160) resources/js/components/editor/modules/YoutubeEmbedModule.vue
/assets/fonts/DINWeb.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime
..
/assets/fonts/DINWeb.eot?#iefix referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb-Medium.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb-Medium.eot?#iefix referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb-Bold.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime
...
/assets/fonts/dinpro-regular-webfont.eot referenced in /Users/user/code/site.com/resources/sass/login.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime
...
/css/images/openhand.cur referenced in /Users/user/code/site.com/resources/js/components/preview/PreviewImageGalleryModule.vue?vue&type=style&index=0&scoped=f693f356&lang.css didn't resolve at build time, it will remain unchanged to be resolved at runtime

/css/images/closedhand.cur referenced in /Users/user/code/site.com/resources/js/components/preview/PreviewImageGalleryModule.vue?vue&type=style&index=0&scoped=f693f356&lang.css didn't resolve at build time, it will remain unchanged to be resolved at runtime
node_modules/vue2-filters/dist/vue2-filters.js (107:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.
...

Fonts are loaded using resources/sass/dashboard/_font.scss:

@font-face {
    font-family: 'DINWeb';
    font-weight: 400;

    src: url('/assets/fonts/DINWeb.eot');
    src: url('/assets/fonts/DINWeb.eot?#iefix') format('embedded-opentype'),
         url('/assets/fonts/DINWeb.woff') format('woff');
}

@font-face {
    font-family: 'DINWeb';
    font-weight: 500;

    src: url('/assets/fonts/DINWeb-Medium.eot');
    src: url('/assets/fonts/DINWeb-Medium.eot?#iefix') format('embedded-opentype'),
         url('/assets/fonts/DINWeb-Medium.woff') format('woff');
}

@font-face {
    font-family: 'DINWeb';
    font-weight: 700;

    src: url('/assets/fonts/DINWeb-Bold.eot');
    src: url('/assets/fonts/DINWeb-Bold.eot?#iefix') format('embedded-opentype'),
         url('/assets/fonts/DINWeb-Bold.woff') format('woff');
}

in resources/sass/dashboard/_font.scss from @import "dashboard/font"; in resources/sass/dashboard.scss The path is correct when loaded from public folder and did work with Laravel Mix..

current Vite configuration

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue2';
import path from 'path';

export default defineConfig({
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.esm.js', // ES module build for Vite
            '@': path.resolve(__dirname, './resources/js'),
            '@vendor': path.resolve(__dirname, './resources/assets/vendor/MediaManager/js'),
            '@store': path.resolve(__dirname, './resources/js/store'),
            '@preview': path.resolve(__dirname, './resources/js/store/preview'),
            '@published': path.resolve(__dirname, './resources/js/store/published'),
            // '~': path.resolve(__dirname, './node_modules')
            '@normalize': './node_modules/normalize.scss/normalize.scss'

        },
        extensions: ['.js', '.jsx', '.json', '.vue']  // Ensure .vue is included here
    },
    plugins: [
        laravel({
            input: [
                'resources/assets/vendor/MediaManager/sass/manager.scss',
                'resources/sass/dashboard.scss',
                'resources/sass/editor.scss',
                'resources/sass/login.scss',
                'resources/sass/preview.scss',
                'resources/sass/published.scss',
                'resources/js/dashboard.js',
                'resources/js/editor.js',
                'resources/js/preview.js',
                'resources/js/published-utils.js',
                'resources/js/published-vendor.js',
                'resources/js/published.js',
            ],
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
});
rhand's avatar
Level 6

Ran

npm install -g sass-migrator
sass-migrator division **/*.scss

To deal with slash div deprecation issue https://sass-lang.com/documentation/breaking-changes/slash-div/ .

Now I stil have to deal with the font import issues mentioned in last post so:

npm run build

> build
> vite build

vite v5.2.12 building for production...
transforming (170) node_modules/axios/lib/core/InterceptorManager.js
/assets/fonts/DINWeb.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb.eot?#iefix referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb-Medium.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb-Medium.eot?#iefix referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb-Bold.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/DINWeb-Bold.eot?#iefix referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/fontawesome-webfont.eot?v=4.7.0 referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0 referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/dinpro-regular-webfont.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/dinpro-bold-webfont.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

../fonts/bootstrap/glyphicons-halflings-regular.eot referenced in /Users/user/code/site.com/resources/sass/published.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

../fonts/bootstrap/glyphicons-halflings-regular.eot?#iefix referenced in /Users/user/code/site.com/resources/sass/published.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/icomoon.eot?ylc32v referenced in /Users/user/code/site.com/resources/sass/published.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/icomoon.eot?ylc32v#iefix referenced in /Users/user/code/site.com/resources/sass/published.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/img/dropdown.ico referenced in /Users/user/code/site.com/resources/sass/published.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/fontawesome-webfont.eot?v=4.7.0 referenced in /Users/user/code/site.com/resources/sass/published.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0 referenced in /Users/user/code/site.com/resources/sass/published.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

../fonts/bootstrap/glyphicons-halflings-regular.eot referenced in /Users/user/code/site.com/resources/sass/preview.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

../fonts/bootstrap/glyphicons-halflings-regular.eot?#iefix referenced in /Users/user/code/site.com/resources/sass/preview.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

/assets/fonts/icomoon.eot?ylc32v referenced in /Users/user/code/site.com/resources/sass/preview.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime
...

Read something on using

...
build: {
    rollupOptions: {
      input: 'resources/js/main.js', // adjust according to your entry point
      output: {
        assetFileNames: 'assets/[name].[ext]',
      },
    },
  },
...

in Vite configuration , but not sure yet about all this. How would I make

src: url('/assets/fonts/DINWeb.eot');

in resources/sass/dashboard/_font.scss loaded from resources/sass/dashboard.scss with

@import "dashboard/font";

get taken in on time for build? Cannot change path and add public though they are loaded from there... this as the final css cannot see that in the path. Reading https://laracasts.com/discuss/channels/vite/vite-and-fontawesome-files-not-being-copied-to-public now

rhand's avatar
Level 6

When I use

@font-face {
    font-family: 'DINWeb';
    font-weight: 400;

    src: url('/resources/assets/fonts/DINWeb.eot');
    src: url('/resources/assets/fonts/DINWeb.eot?#iefix') format('embedded-opentype'),
         url('/resources/assets/fonts/DINWeb.woff') format('woff');
}

@font-face {
    font-family: 'DINWeb';
    font-weight: 500;

    src: url('/resources/assets/fonts/DINWeb-Medium.eot');
    src: url('/resources/assets/fonts/DINWeb-Medium.eot?#iefix') format('embedded-opentype'),
         url('/resources/assets/fonts/DINWeb-Medium.woff') format('woff');
}

@font-face {
    font-family: 'DINWeb';
    font-weight: 700;

    src: url('/resources/assets/fonts/DINWeb-Bold.eot');
    src: url('/resources/assets/fonts/DINWeb-Bold.eot?#iefix') format('embedded-opentype'),
         url('/resources/assets/fonts/DINWeb-Bold.woff') format('woff');
}

and copy over the fonts from the public directory - like public/assets/fonts/dinpro-regular-webfont.eot from there - to /resources/assets/fonts/ they do load. But not sure if this is the way to go yet. And then I stil have fontawesome fonts to deal with.

rhand's avatar
Level 6

Changing path and adding public did not help. Using ../public/assets/fonts/.. did not help. Copying files over from public folder to assets/fonts folder did not help. Using Vite

...
import { viteStaticCopy } from 'vite-plugin-static-copy';
...
viteStaticCopy({
            targets: [
                {
                    src: 'public/assets/fonts/*',
                    dest: 'assets/fonts',
                },
            ],
        }),
...

Did not help. Always issues like

transforming (131) resources/js/components/preview/PreviewTextModule.vue
../../assets/fonts/fontawesome-webfont.eot referenced in /Users/user/code/site.com/resources/sass/dashboard.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime

referring to issue resolving on built time. How does anyone deal with sass in Vite at all using font references?

rhand's avatar
Level 6

Added Vite aliases:

$fonts: path.resolve(__dirname, './public/assets/fonts'),
 $img: path.resolve(__dirname, './public/img')

and used $font in sass font paths like

@font-face {
    font-family: 'FontAwesome';
    src: url('$fonts/fontawesome-webfont.eot?v=4.7.0');
    src: url('$fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), 
    url('$fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), 
    url('$fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), 
    url('$fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), 
    url('$fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
  }

and that works. Not sure about frontend loading yet as builds still fail however .Only login.scss does not seem to accept this update showing

vite v5.2.12 building for production...
transforming (144) resources/js/components/preview/PreviewEmbeddedTweetModule.vue
../fonts/fontawesome-webfont.eot?v=4.7.0 referenced in /Users/user/code/site.com/resources/sass/login.scss didn't resolve at build time, it will remain unchanged to be resolved at runtime
rhand's avatar
Level 6

Added these aliases in the end

...
$fonts': path.resolve(__dirname, './public/assets/fonts'),
'$img': path.resolve(__dirname, './public/img'),
'$slider_img': path.resolve(__dirname, './public/css/images'),
 '$sass': path.resolve(__dirname, './resources/sass'),
...

but the sass alias seems to cause one issue with an NPM package

npm run build

> build
> vite build

vite v5.2.12 building for production...
transforming (189) node_modules/sortablejs/modular/sortable.esm.js[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "$sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "$sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
4  |  audio {
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "$sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |

Not sure why the node module is also using the alias. But could be related to VueDraggable we do use. Not sure how to deal with this issue now in Vite though . Got sass font paths and other paths to load and now this..

rhand's avatar
Level 6

When I use @sass for Vite alias for sass

'@sass': path.resolve(__dirname, './resources/sass'),

and replaced all $sass with @sass in Vue files I got less errors but still this one:

npm run build

> build
> vite build

vite v5.2.12 building for production...
transforming (244) resources/js/mixins/Modal.js[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "@sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "@sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
4  |  audio {
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "@sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
node_modules/vue2-filters/dist/vue2-filters.js (107:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification

Not sure why the _variables.scss is empty. resources/sass/_variables.scss does contain


$editor-background-color: #373C43;
$grid-background-color: #FFF;
$smart-orange: #ED821C;
$input-border-blue: #B0BAD0;
$input-text-gray: #768391;
$input-btn-secondary: #79838f;
$input-x-transform: translateX(10px);

Other issue is that assets are build in public/build/assets/openhand-DtcxGXAC.cur and I do not want built added to the path. And all seem to be added with a random string at the end.

rhand's avatar
Level 6

Well I decided not to change the paths and work with aliases but move / duplicate all assets in root assets directory. Then I had to adjust a few scss paths but this works well. But do get back to this error

npm run build

> build
> vite build

vite v5.2.12 building for production...
transforming (263) resources/js/components/editor/sidebar/ActiveModule.vue[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "../../../../sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "../../../../sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
4  |  audio {
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "../../../../sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
node_modules/vue2-filters/dist/vue2-filters.js (107:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.

So the _variable.scss file error being empty while resources/sass/_variables.scss has content still pops up for most Vue components, whether they use or not use this scss file. The file resources/js/components/editor/sidebar/ActiveModule.vue does not import this Sass file and has scoped style . The file resources/js/components/editor/sidebar/inputs/AudioInput.vue does load it using @import "../../../../../sass/_variables.scss";

@import "../../../../sass/_variables.scss";

is used in 8 files as import . Like

...
<style type="scss">
@import "../../../../sass/_variables.scss";
...

or

...
style lang="scss">
    @import "../../../../sass/_variables.scss";
...

And when I replace all _variables.scss loading in Vue components by this path @import "/resources/sass/_variables.scss"; I still see

npm run build

> build
> vite build

vite v5.2.12 building for production...
transforming (252) resources/js/components/editor/sidebar/inputs/HtmlEditorInput.vue[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "/resources/sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
4  |  audio {
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "/resources/sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |
[vite:css] /Users/user/code/site.com/resources/sass/_variables.scss is empty
1  |
2  |  @import "/resources/sass/_variables.scss";
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |   (x2)

Perhaps Vite does not yet deal with variables added in _variables.scss:


$editor-background-color: #373C43;
$grid-background-color: #FFF;
$smart-orange: #ED821C;
$input-border-blue: #B0BAD0;
$input-text-gray: #768391;
$input-btn-secondary: #79838f;
$input-x-transform: translateX(10px);

But why and how to fix this?

rhand's avatar
Level 6

Using @use "/resources/sass/_variables.scss"; so @use - see https://sass-lang.com/documentation/at-rules/use/ instead of@import` seems to work

Use the @use directive instead of @import: The @use directive is a newer way of importing Sass files in Vue components. It's similar to @import, but it allows Vite to process the contents of the imported file.

Now I am closer yet again

npm run build

> build
> vite build

vite v5.2.12 building for production...
node_modules/vue2-filters/dist/vue2-filters.js (107:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.
node_modules/vue2-filters/dist/vue2-filters.js (119:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.
node_modules/vue2-filters/dist/vue2-filters.js (131:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.
node_modules/vue2-filters/dist/vue2-filters.js (143:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.
...
✓ 473 modules transformed.
Generated an empty chunk: "published-utils".
public/build/assets/closedhand-mUMzHGu0.cur                       0.33 kB
public/build/assets/openhand-DtcxGXAC.cur                         0.33 kB
public/build/assets/icomoon-wpKxneEb.ttf                          2.43 kB
public/build/assets/icomoon-BqCl43Pk.woff                         2.51 kB
public/build/assets/icomoon-Drq6sACt.eot                          2.60 kB
....
public/build/assets/SidebarModuleSettings-DJY55GoH.js            10.11 kB │ gzip:   2.23 kB
public/build/assets/Page-CeHHMBFu.js                             10.96 kB │ gzip:   3.28 kB
public/build/assets/EditPageModal-_tyHL7Rk.js                    11.19 kB │ gzip:   3.08 kB
public/build/assets/PublishedModule-Bv3pQsxT.js                  11.58 kB │ gzip:   2.53 kB
public/build/assets/MenuModule-DFaCCXGN.js                       13.53 kB │ gzip:   3.24 kB
public/build/assets/vue-cookies-Cz2HVUWu.js                      14.70 kB │ gzip:   4.76 kB
public/build/assets/MenuModal-CdMLx7C1.js                        16.60 kB │ gzip:   4.09 kB
public/build/assets/ContactModule-Cv5vMZY3.js                    17.37 kB │ gzip:   4.74 kB
public/build/assets/Editor-CGTeS9lf.js                           22.26 kB │ gzip:   7.27 kB
public/build/assets/vue-router.esm-Bs0zlJpX.js                   24.40 kB │ gzip:   8.78 kB
public/build/assets/Sidebar-Dq9hFblw.js                          26.98 kB │ gzip:   5.52 kB
public/build/assets/index-BSXUom1u.js                            30.32 kB │ gzip:   7.44 kB
public/build/assets/ImageGalleryModal-CSzysTmP.js                32.61 kB │ gzip:   7.58 kB
public/build/assets/SliderGalleryModal-Binxvyd3.js               33.97 kB │ gzip:   7.85 kB
public/build/assets/bugsnag-vue-CTci2AoM.js                      68.76 kB │ gzip:  20.23 kB
public/build/assets/vuedraggable.umd-Dfu9uvaY.js                 71.40 kB │ gzip:  25.02 kB
public/build/assets/index-YVYFBVP_.js                            88.90 kB │ gzip:  33.03 kB
public/build/assets/vuex.esm-DwB78Rcz.js                         90.38 kB │ gzip:  32.06 kB
public/build/assets/ColorPickerModal-12lRtVg3.js                119.04 kB │ gzip:  33.88 kB
public/build/assets/editor-Kiwr2_mi.js                          695.91 kB │ gzip: 217.32 kB

(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 3.88s

with chunk resources/js/published-vendor.js empty for some reason. And @vite('resources/css/login.css') does not work. But that is due to build setup I believe.

rhand's avatar
Level 6

Issue with public/css/login.css or the versions with hashes loading but build is working

npm run build

> build
> vite build

vite v5.2.12 building for production...
node_modules/vue2-filters/dist/vue2-filters.js (107:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.
...
node_modules/vue2-filters/dist/vue2-filters.js (299:0): Use of eval in "node_modules/vue2-filters/dist/vue2-filters.js" is strongly discouraged as it poses security risks and may cause issues with minification.
✓ 473 modules transformed.
Generated an empty chunk: "published-utils".
public/build/assets/openhand-DtcxGXAC.cur                         0.33 kB
public/build/assets/closedhand-mUMzHGu0.cur                       0.33 kB
public/build/assets/icomoon-wpKxneEb.ttf                          2.43 kB
public/build/assets/icomoon-BqCl43Pk.woff                         2.51 kB
...
public/build/assets/vuedraggable.umd-Dfu9uvaY.js                 71.40 kB │ gzip:  25.02 kB
public/build/assets/index-YVYFBVP_.js                            88.90 kB │ gzip:  33.03 kB
public/build/assets/vuex.esm-DwB78Rcz.js                         90.38 kB │ gzip:  32.06 kB
public/build/assets/ColorPickerModal-12lRtVg3.js                119.04 kB │ gzip:  33.88 kB
public/build/assets/editor-Kiwr2_mi.js                          695.91 kB │ gzip: 217.32 kB

(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 4.06s

@vite('resources/css/login.css') in resources/views/ayouts/app.blade.php&line=14 is incorrect. Build shows

public/build/assets/login-CkTLembl.css 

How to get it it load properly ?

Please or to participate in this conversation.