pc579's avatar
Level 1

Webpack / Mix - how to change a script directory?

I get the error "Can't resolve '../api" running "npm run dev"

I wrote a script to retrieve some data via an api call.

This script works well when I put it in the vendor directory (vendor/badaso/core/src/js/api/modules) It is called by a store in resources/js/badaso/stores with

import api from "../../../../vendor/badaso/core/src/resources/js/api";

When I move this script to resources/js/badaso/api/modules and call it by

import "../api"

Running "npm run dev", I get the error

Can't resolve '../api

My webpack.mix.js is

const mix = require('laravel-mix');

//mix.js('resources/js/app.js', 'public/js')                              // original
mix.js('resources/js/*.js', 'public/js')                                    // try -> same error
    .postCss('resources/css/app.css', 'public/css', [
        //
    ]);
// Can't resolve '../api'

// Badaso
mix.js("vendor/badaso/core/src/resources/js/app.js", "public/js/badaso.js")
    .sass("vendor/badaso/core/src/resources/js/assets/scss/style.scss", "public/css/badaso.css")
    .vue()

Thanks in advance for any help

0 likes
6 replies
AungHtetPaing__'s avatar

@pc579 check folder or file path. ../ depend on file location you writing import "../api". Use @ which is alias for path resources/js.

1 like
pc579's avatar
Level 1

Hi @aunghtetpaing__

Thanks for your answer, maybe Im not awake this morning but I did not find any problem with file location and when I try "import api from "@api";" I got the same error as before

Module not found: Error: Can't resolve '@api' in '/var/www/html/Laravel9/Bon/resources/js/badaso/stores'

pc579's avatar
Level 1

Thanks @sinnbeck for your enlightenment, so let's continue to try without alias , it should work since I just change a path where I moved the script.

So with "import api from "../api";" I got the error

Module not found: Error: Can't resolve '../api' in '/var/www/html/Laravel9/Bon/resources/js/badaso/stores'

But, for me, the module seems to be there

ls  /var/www/html/Laravel9/Bon/resources/js/badaso/stores/../api
//modules  readme.MD
ls  /var/www/html/Laravel9/Bon/resources/js/badaso/stores/../api/modules
// my_module.js
AungHtetPaing__'s avatar

@pc579 is the api folder inside resources/js/badaso/api or resources/js/badaso/stores/....../api? I can't find another problem rather than wrong file path.

1 like

Please or to participate in this conversation.