简体   繁体   English

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

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

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/login I am shown the login page:但是,当我访问http://cms.test/login时,会看到登录页面:

在此处输入图片说明

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 文件外都是空的,这正常吗?

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

The app.css and app.js were missing from a new app.新应用中缺少 app.css 和 app.js。 The proper steps had been run as are noted in Jack Robson's answer above.正如上面 Jack Robson 的回答中所指出的那样,已经运行了正确的步骤。 I reran the last two steps:我重新运行了最后两个步骤:

    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.不知道初始安装出了什么问题。

下面的命令对我有用。

npm install && npm run dev

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.一切正常。

The reason the files are missing is you forgot to run the build process that generates the files.文件丢失的原因是您忘记运行生成文件的构建过程。 The last command npm run dev does this.最后一个命令npm run dev执行此操作。 Having the 2 commands paired ( npm install && npm run dev ) in the docs seems to be catching a lot of people out.在文档中将 2 个命令配对( npm install && npm run dev )似乎吸引了很多人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Laravel 中的 app.js 和 app.css 修复错误 404? - How to fix error 404 with app.js and app.css in Laravel? App.css 和 App.js 在 npm 运行 dev 之后在 laravel 9 中仍然找不到 - App.css and App.js still not found in laravel 9 after npm run dev JetStream CSS 和 JS 不工作并显示 @vite(['resources/css/app.css', 'resources/js/app.js']) - JetStream CSS and JS not working and showing @vite(['resources/css/app.css', 'resources/js/app.js']) Laravel app.js和app.css为什么需要使用? 我们可以删除那些吗? - Laravel app.js and app.css why need to use ? Can we removed those? VueJ的最佳实践,使用laravel混合和放置app.js以及sass的bootstrap和app.css - Best Practice for VueJs using laravel mix and placement app.js with bootstrap and app.css from sass laravel 微风 app.css,检查时 app.js 缺失 - laravel breeze app.css, app.js missing when inspected Laravel 根目录已更新,npm 运行 dev 在错误的目录中创建 app.css 和 app.js - Laravel root directory updated, npm run dev creating app.css and app.js in wrong directory Laravel 9 - GET http://localhost:8000/css/app.css.net::ERR_ABORTED 404(未找到) - Laravel 9 - GET http://localhost:8000/css/app.css net::ERR_ABORTED 404 (Not Found) Laravel 8 - GET http://localhost:8000/css/app.css.net::ERR_ABORTED 404(未找到) - Laravel 8 - GET http://localhost:8000/css/app.css net::ERR_ABORTED 404 (Not Found) Laravel混合,在资源中调用app.js - Laravel mix, call app.js in resources
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM