0

So I'm using Vue 3 and Router. The site functions greatly when I do npm run dev. Now if I got this correct, I have to do npm run build for the site before I put it on something like netify right.

This created a dist folder, in the folder is an index.html file. It opens up blank?
I go to check the console log and see these errors

Access to script at 'file:///Z:/assets/index-64361c69.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

Failed to load resource: net::ERR_FAILED

Failed to load resource: net::ERR_FILE_NOT_FOUND x2

I'm pretty new to all this so do excuse me.

My question is what could be causing the issue for index.html to be blank?

vite.config.ts:

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
 plugins: [
 vue(),
 ],
 resolve: {
 alias: {
 '@': fileURLToPath(new URL('./src', import.meta.url))
 }
 }
})

dist > index.html:

<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="UTF-8">
 <link rel="icon" href="/favicon.ico">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Vite App</title>
 <script type="module" crossorigin src="/assets/index-64361c69.js"></script>
 <link rel="stylesheet" href="/assets/index-9b74bc40.css">
 </head>
 <body>
 <div id="app"></div>
 
 </body>
</html>

index in the folder I do the npm:

<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="UTF-8">
 <link rel="icon" href="/favicon.ico">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Vite App</title>
 </head>
 <body>
 <div id="app"></div>
 <script type="module" src="/src/main.ts"></script>
 </body>
</html>

After this main folder with all the files and where I do the npm stuff, I have a src folder which contains
assets
components
router
views
App.vue
main.ts

Hope this helps.

Fixed my issues.

To get it to work with Netlify I just needed to create a file with: called netlify.toml That contained this [build] command = "npm run build" publish = "dist"

asked Dec 16, 2023 at 14:43
5
  • 1
    This is expected. The dist directory is meant to be served by an HTTP server. It will not work if you open dist/index.html directly over file:// protocol. You can preview the production build with npm run preview if needed. Commented Dec 16, 2023 at 15:15
  • Okay doing npm run preview worked. But I lost the images that I have in my folders. Might be how I have everything set up lol. That stuff is in files called projectFiles.ts. So if that worked, how would I got about for something like Netify - if you know? Commented Dec 16, 2023 at 16:12
  • Netlify is exactly the type of service dist assets are meant to be served from. Follow their documentation and you shouldn't have to do anything to the actual files themselves other than upload. Commented Dec 16, 2023 at 16:29
  • With Netlify I have tried to launch up a site. But it popped up with an error, if I do npm run build then it will just be a blank vite page. Should I do that as npm run preview. I'll have a look at thair documentation. I saw a video and it looked simple for the guy to just use his GitHub account which I was aiming to do. Commented Dec 16, 2023 at 17:40
  • I managed to get it to work on Netify buy creating a file called netlify.toml with: [build] command = "npm run build" publish = "dist" Commented Dec 17, 2023 at 15:43

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.