Laravel 6.0.3 未加载关键资源 App.js 或 App.css 404 Not Found

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/57940718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:21:58  来源:igfitidea点击:

Laravel 6.0.3 Not Loading Key Resources App.js or App.css 404 Not Found

laravellaravel-6

提问by Hyman Robson

To setup my project I ran:

为了设置我的项目,我跑了:

laravel new cms
composer require laravel/ui
php artisan ui:auth
php artisan migrate

However, when I go to http://cms.test/loginI am shown the login page:

但是,当我访问http://cms.test/login时,会看到登录页面:

enter image description here

在此处输入图片说明

And get two 404 errors for missing resources:

并因缺少资源而得到两个 404 错误:

http://cms.test/js/app.js net::ERR_ABORTED 404 (Not Found)
http://cms.test/css/app.css

What could be the reason for these missing files?

这些丢失文件的原因可能是什么?

My public directory is empty aside from .htaccess, favicon.ico, index.php and robot.txt files, is that normal?

我的公共目录除了.htaccess、favicon.ico、index.php 和robot.txt 文件外都是空的,这正常吗?

回答by Hyman Robson

My setup was a little wrong, I mostly forgetting to run npm install and npm run dev command that is required to compile the app.js and app.css files.

我的设置有点错误,我主要是忘记运行编译 app.js 和 app.css 文件所需的 npm install 和 npm run dev 命令。

Correct setup command sequence was:

正确的设置命令序列是:

laravel new cms
cd cms
php artisan migrate
composer require laravel/ui
npm install
php artisan ui vue --auth
npm install && npm run dev

回答by G-Man

The app.css and app.js were missing from a new app. The proper steps had been run as are noted in Hyman Robson's answer above. I reran the last two steps:

新应用中缺少 app.css 和 app.js。正如上面 Hyman Robson 的回答中所指出的那样,已经运行了正确的步骤。我重新运行了最后两个步骤:

    php artisan ui vue --auth
    npm install && npm run dev

And it generated the app.css and app.js - all good now.

它生成了 app.css 和 app.js - 现在一切都很好。

No idea what had gone wrong in the initial install.

不知道初始安装出了什么问题。

回答by Aezur

The reason the files are missing is you forgot to run the build process that generates the files. The last command npm run devdoes this. Having the 2 commands paired (npm install && npm run dev) in the docs seems to be catching a lot of people out.

文件丢失的原因是您忘记运行生成文件的构建过程。最后一个命令npm run dev执行此操作。在npm install && npm run dev文档中将 2 个命令配对 ( ) 似乎吸引了很多人。

回答by Marcelo Juan Cabrera Gutierrez

In my case it was: that when configuring the Virtual Host in Apache wrote the path to the folder incorrectly: DocumentRoot "D: \ LARAVEL \ instagrmalaravel \ public"...

就我而言,它是:在 Apache 中配置虚拟主机时错误地写入了文件夹的路径: DocumentRoot "D:\LARAVEL\instagrmalaravel\public"...

when on host it was: 127.0.0.1 instagramlaravel.local,

在主机上时它是: 127.0.0.1 instagramlaravel.local,

change: instagrmalaravel to: instagramlaravel.

将:instagramlararavel更改为:instagramlaravel。

And everything worked correctly.

一切正常。