Migrating Nuxt project to Quasar - Absolute path



  • Hi,

    I just started to migrate project from Nuxt to Quasar. I have a problem with importing modules.
    I would like to import using absolute path like Nuxt:

    import { objectActions } from '~/util/defs';
    

    but it is not working

    This dependency was not found:
    
    * ~/util/defs in ./node_modules/babel-loader/lib??ref--1-0!./node_modules/@quasar/app/lib/webpack/loader.auto-import.js?kebab!./node_modules/vue-loader/lib??vue-loader-options!./src/pages/Index.vue?vue&type=script&lang=js&
    
    To install it, you can run: npm install --save ~/util/defs
    

    It doesn’t work either

    import { objectActions } from '@util/defs';
    

    After change to relative path is OK.

    import { objectActions } from '../util/defs';
    

    I tried to move my module to folder components, pages and it’s work!

    import { objectActions } from 'components/defs';
    

    I guess it’s a Webpack problem but I don’t know much about it yet.

    How to get to the root of the project in Quasar?
    How can I define an additional folder so that I can reference it like ‘components/…’, ‘pages/…’, etc.?

    Regards



  • I think I found a solution. I don’t know if it’s the correct, but it works.
    In the quasar.conf.js file I added:

    // Full list of options: https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-build
        build: {
          ...
          extendWebpack (cfg) {
            cfg.resolve.alias = {
              ...cfg.resolve.alias,
              '~/util': path.resolve(__dirname, './src/util')
            }
            ...
          }
          ...
        },
    

Log in to reply