Static JS file not loading on Dynamic page in nuxtJS - vue.js

Script is loading just fine in other pages but not loading on dynamic pages in NuxtJS. My nuxt.config.js file reference -
head: {
script:[
{ src: 'test.min.js' }
],
}
[NB] The test.min.js file is in root of static directory.
Dynamic route e.g. products/_slug/index.vue
GET http://localhost:3000/products/abc-def/test.min.js net::ERR_ABORTED 404 (Not Found)
Can you please help me resolve this issue? Thank you.

Try to specify an absolute path with something like
/test.min.js
#/test.min.js // or maybe this one
##/test.min.js // or even this one

You have to specify an absolute path as kissu mentioned and also you can try this:
~/test.min.js
In many times it works too

Related

How to get Nuxt-img to work on nuxt3 generate?

i am trying to use nuxt-image on NUXT3, but it seems it doesn't work with the generate command. Images work during dev, but get a 404 when using nuxt generate.
in my nuxt config i have
modules: ["#nuxt/image-edge"],
image: {
dir: "assets/images",
},
then in my files i have
<NuxtImg
format="webp"
class="mobile"
src="/website/home/above-fold-illustration-mobile.png"
alt="illustration"
aria-hidden="true"
/>
So i am wondering if anyone else had a problem or if this is just a compatibility issue with nuxt-image and nuxt3 generate
this is not yet supported, waiting on https://github.com/nuxt/image/pull/614
Reading this part of the documentation
For static provider, if images weren't crawled during generation (unreachable modals, pages or dynamic runtime size), changing dir from static causes 404 errors.
There are other few bugs if you change dir to something else than static apparently.
Can't you stick to static? Will probably avoid you quite some issues IMO.

Creating multi-page application with Vue CLI3.0, how to handle this error?

I am a beginner of Vue and I am trying to build a multi-page web application with Vue for practice. But I am having this problem below:
Failed to compile.
./src/index/views/Home.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/index/views/Home.vue?vue&type=script&lang=js&)
Module not found: Error: Can't resolve '#/components/HelloWorld.vue' in '/home/Username/Web/wk_front_end/src/index/views'
Here is the file tree of my project, every file is generated by Vue because I only want to test the multi-page, so I think it wouldn't be a coding problem.
Here is what I did:
I created a folder called the index under the src folder, I then move all the files and folders that originally under src to index because I wish the components and assets are only used in the corresponding page.
My vue.config.js is:
module.exports = {
pages: {
index: {
entry: "src/index/main.js",
template: "src/index/index.html",
filename: "index.html",
title: "Index Page"
},
}
}
When I try to run it, I got the error above on the chrome window. And actually, the error is:
I think it might be caused by missing of configurations, but I really cannot figure out what those other configurations I need.
Does anyone have similar problem before? Does anyone know how to solve it? Or, does anyone have some successful multi-page example that I could take a look?
Really thanks for the help.
I believe # is a shortcut for the src folder. Which would mean your current path resolves to src/components/HelloWorld.vue.
You could try doing #/index/components/HelloWorld.vue, which should be the correct path.
From my sight you may be importing your Vue components incorrectly. If you want to make multi-page-app why don't you try vue-router ? Maybe it's not the direct solution for your problem but it will help you to better manage your pages (routes) in the future.

chunks file urls problem in laravel and vuejs

i am developing a web application with laravel and vue
i deploy application in this route in host:
https://novintech.info/panel
anything is true but chunks file have wrong path and refer to:
https://novintech.info
for example:
https://novintech.info/js/home.js //this is chunk file
how to refrence this file to:
https://novintech.info/panel/js/home.js
please help. thanks
problem solved by adding output.publicPath property in webpackconfig
mix.webpackConfig({
output: {
publicPath: 'https://novintech.info/info/public/',
}
});
Once you ran the production script, go to the file generated folder public/, open the file app.js in an editor.
Research for js/chunk and replace it by info/public/js/chunk.

Can't find static assets from express/npm module

tldr;
My project is an NPM module that is used by an ExpressJS server. The server needs to specify an endpoint and my module will do the rest. How do I get my module to load the correct html page and grab the correct js/css files from the correct path?
The Problem
I'm running into a problem where I can see the directory structure of the site, using the serveIndex library, and all the files are in their correct directories but for some reason when I try to load any of the files, whether from the serveIndex view or from the actual endpoint where it should load, I get nothing but 404 errors.
Here's an example if someone wanted to use this NPM module from their project.
app.js (their server)
const express = require('express')
const { adminAreaConfig } = require('express-admin-area')
const app = express()
const adminArea = adminAreaConfig(express) // my module being passed the "express" library
app.use('/admin', adminArea) // specify a URL to use my module
app.listen(3000, () => console.log('\n\nServer Online\n\n'))
Here's an image of my projects dir structure after it's been built.
Going off of a console.log(__dirname), which returns <long path string>/express-admin-area/build/src, I then tell my module, using the express reference passed by the actual server in the code above, to look in the views directory with
... import libraries etc ...
const adminAreaConfig = express => {
const adminArea = express.Router()
adminArea.use('/', express.static(__dirname + '/views') // sets my modules views to the "http://localhost:3000/admin" path
adminArea.use('/dirs', serveIndex(__dirname)) // will get into this later
... some other stuff like exports etc ...
This then attempts to load the index.html file in the express-admin-area/build/src/views directory but fails because it can't locate the CSS and JS files inside express-admin-area/build/src/views/static/css or .../js.
First, I know it fails because instead of looking for http://localhost:3000/admin/static/css/styles.css it looks for http://localhost:3000/static/css/styles.css, so that's another problem I need to solve entirely.
Second, looking back at the small code sample above, adminArea.use('/dirs', serveIndex(__dirname)), I'm using the serveIndex library in an attempt to view the directory structure. If I go to http://localhost:3000/admin/dirs I get the correct directories and files in the browser
But now, if I try to view an actual file I'm met with the error Cannot GET /admin/dir/main.js for example if I were to go to http://localhost:3000/admin/dir/main.js, but I can continue going deeper in the directories if I wanted such as the controllers or routes directories from the image.
What I want
I need a way to get these static assets to load. If I point my module to a basic html page with a simple <h1>Hello, World!</h1> then that's what Ill get but trying to load any outside scripts/stylesheets is when I get the 404 errors and nothing loads.
I'll be answering my own question.
The solution is actually pretty simple. The view layer of this module is handled by React, CRA to be specific. CRA will look for some specific environment variables, one of them being PUBLIC_URL. All I had to do was
Create a .env file in the root directory of my CRA
add PUBLIC_URL="/admin"
Afterward, it's just rebuilding the project, yarn build, and reset the server. CRA will then look at http://localhost:3000/admin/static/... instead of http://localhost:3000/static/... for static assets.

Is it possible to add a request parameter to dojo module requests via dojo's AMD loader

Is it possible to modify request urls used by the dojo AMD loader before a request is sent to the server for an AMD module? I would like to append a request parameter with a version number.
The problem we are trying to solve is that we want our javascript files to be cached by the browser unless the application's version is updated. I think we should be able to do that if we can add a version number to the requested URL.
The paths config property seems to work for individual modules, and cacheBust can be used for all modules. Example jsfiddle.
<script>
var dojoConfig = {
paths: {
// version a single file by using path with version number
"aa": "mylib-aa.js?v=1.0",
// standard path, no explicit versioning
"bb": "mylib-bb"
},
// use v=1.0 for ALL loaded modules
cacheBust: "v=1.0",
waitSeconds: 10
};
</script>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script>
<script>
require(["aa", "bb"], function () {});
</script>
Giving:
"NetworkError: 404 Not Found - https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/mylib-aa.js?v=1.0.js&v=1.0"
"NetworkError: 404 Not Found - https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/mylib-bb.js?v=1.0"
The hiccup for the paths approach is the trailing ".js", but for the purposes of versioning I don't think that's an issue as the URL is still unique in the way you want it to be.