I am new in Laravel. I am trying to run gulp command in CMD to get CSS and JS (vue.js) file. I am getting following error while I am trying to run gulp command in CMD. I am using Laravel 5.3.
{ [Error: ./resources/assets/js/app.js
Module build failed: ReferenceError: Unknown plugin "add-module-exports" specified in "base" at 0, attempted to resolve relative to "D:\\php7\\htdocs\\addbook\\
resources\\assets\\js" at D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:176:17
at Array.map (native) at Function.normalisePlugins (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:154:20)
at OptionManager.mergeOptions (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:229:36)
at OptionManager.init (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\options\option-manager.js:374:12)
at File.initOptions (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\index.js:216:65)
at new File (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\file\index.js:139:24)
at Pipeline.transform (D:\php7\htdocs\addbook\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
at transpile (D:\php7\htdocs\addbook\node_modules\babel-loader\index.js:38:20)
at Object.module.exports (D:\php7\htdocs\addbook\node_modules\babel-loader\index.js:131:12)]
message: './resources/assets/js/app.js\nModule build failed: ReferenceError: Unknown plugin "add-module-exports" specified in "base" at 0, attempted to resolv
e relative to "D:\\\\php7\\\\htdocs\\\\addbook\\\\resources\\\\assets\\\\js"\n at D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\f
ile\\options\\option-manager.js:176:17\n at Array.map (native)\n at Function.normalisePlugins (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\t
ransformation\\file\\options\\option-manager.js:154:20)\n at OptionManager.mergeOptions (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transforma
tion\\file\\options\\option-manager.js:229:36)\n at OptionManager.init (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\file\\optio
ns\\option-manager.js:374:12)\n at File.initOptions (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\file\\index.js:216:65)\n at
new File (D:\\php7\\htdocs\\addbook\\node_modules\\babel-core\\lib\\transformation\\file\\index.js:139:24)\n at Pipeline.transform (D:\\php7\\htdocs\\addboo
k\\node_modules\\babel-core\\lib\\transformation\\pipeline.js:46:16)\n at transpile (D:\\php7\\htdocs\\addbook\\node_modules\\babel-loader\\index.js:38:20)\n
at Object.module.exports (D:\\php7\\htdocs\\addbook\\node_modules\\babel-loader\\index.js:131:12)',
showStack: false,
showProperties: true,
plugin: 'webpack-stream',
__safety: { toString: [Function: bound ] } }
Could anyone give me any solution regarding this ?
gulpfile.js
var elixir = require('laravel-elixir');
require('laravel-elixir-vue');
elixir(function(mix) {
mix.sass('app.scss');
});
elixir(function(mix) {
mix.webpack('app.js');
});
elixir(function(mix) {
mix.version(['css/app.css', 'js/app.js']);
});
From the Laravel Docs:
If you are developing on a Windows system or you are running your VM
on a Windows host system, you may need to run the npm install command
with the --no-bin-links switch enabled:
npm install --no-bin-links
Laravel Docs: Elixir Installation and Setup
Remove /node_modules and run npm install with the --no-bin-links switch like mentioned in the docs and quoted above.
Related
I've installed mjml cli using the following command (as described in the mjml documentation):
npm install mjml --save
now if i did node_modules/.bin/mjml in the command line it will run successfully.
the problem is when i use the symfony process component in php i got the following error (even if it's the right path):
The command "/Users/qoraiche/Documents/my-app/node_modules/.bin/mjml" failed. Exit Code: 127(Command not found) Working directory: /Users/qoraicheOS/Documents/my-app/public Output: ================ Error Output: ================ env: node: No such file or directory
Symfony process code:
$process = new Process(base_path('node_modules/.bin/mjml'));
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
By the way i have installed mjml globally as well and try it with no luck.
Try providing the full path to node.js when calling the MJML binary from a Symfony Process().
$process = new Process('/your/path/to/node ' . base_path('node_modules/.bin/mjml'));
I use this method in my own apps. Of course, you will need to provide the input and output files to actually transpile anything.
I'm experimenting with Deployer to deploy Laravel application into shared hosting (using laravel recipe) from my local ~/Code/project_foo.
The point is that when I'm connected to my shared hosting server via ssh, then default php -v version is 5.6.33. I confirmed that I can change php version on fly by calling php70 -v or even whole path like /usr/local/bin/php70 whatever.
The point is that I don't know how to tell deployer to call commands using php70 which is required, otherwise composer install fails.
So in Terminal I'm inside root of the Laravel project and I simply call:
dep deploy
My deploy.php is messy and very simple but this is just a proof of concept. I'm trying to figure out everything and then I will make it look nicer.
I checked the source code of the laravel recipe, and I saw that there is:
{{bin/php}}
but I don't know how to override the value to match what my hosting tells me to use:
/usr/local/bin/php70
Please, give me any hints how to force the script use different PHP version once connected to the remote host / server.
This is whole script:
<?php
namespace Deployer;
require 'recipe/laravel.php';
//env('bin/php', '/usr/local/bin/php70'); // <- I thought that this will work but it doesn't change anything
// Project name
set('application', 'my_project');
// Project repository
set('repository', 'git#github.com:xxx/xxx.git');
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);
// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);
// Writable dirs by web server
add('writable_dirs', []);
// Hosts
host('xxx')
->user('xxx')
->set('deploy_path', '/home/slickpl/projects/xxx');
// Tasks
task('build', function () {
run('cd {{release_path}} && build');
});
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// Migrate database before symlink new release.
before('deploy:symlink', 'artisan:migrate');
OK, I've found the solution.
I added (after require):
set('bin/php', function () {
return '/usr/local/bin/php70';
});
For anybody who searches for changing Composer's PHP version:
set('bin/composer', function () {
return '/usr/bin/php7.4 /usr/local/bin/composer';
});
There is function locateBinaryPath()
so result is:
set('bin/php', function () {
return locateBinaryPath('php7.4');
});
first found php path and composer path use this
for more information Setting PHP versions in Deployer deployments
find / -type f -name "php" 2>&1 | grep -v "Permission denied"
find / -type f -name "composer" 2>&1 | grep -v "Permission denied"
then
set('bin/composer',
function () {
return 'php_path composer_path';
});
like this
set('bin/composer',
function () {
return '/opt/remi/php73/root/usr/bin/php /usr/bin/composer';
});
I'm trying to use Elixir BrowserSync, one of the newest features of Laravel.
I added it to the gulp file
elixir(function(mix) {
mix.sass('app.scss')
.browserSync();
});
when I run "gulp watch" it output this message
[20:49:20] Using gulpfile ~/Desktop/laravel/gulpfile.js
[20:49:20] Starting 'watch'...
[20:49:20] Finished 'watch' after 11 ms
[BS] Proxying: http://homestead.app
[BS] Access URLs:
----------------------------------
Local: http://localhost:3000
External: http://10.9.0.48:3000
Automatically a browser is launched with the url http://localhost:3000 but nothing loads.
I think the problem is related to this line:
[BS] Proxying: http://homestead.app
You can if you use BrowserSyncs server.
mix.browserSync({
proxy: false,
server: {
baseDir: './'
}
});
Are you running multiple homestead sites? It looks like it defaults to proxying through homestead.app if you do not include a proxy setting. If you don't host your local on homestead.app it won't find it.
Try
.browserSync({ proxy: 'domain.app' });
Where domain.app is what you are serving the site with.
The direct answer to your question - it is not possible to not proxy the .browserSync. Long side-answer - you can still use elixir's implementation of browserSync in gulp, but you must have a separate PHP server to interpret the files.
Edit: I saw a way to not proxy by providing the script in the pages manually (by not giving any arguments in the .browserSync() call, but don't remember where and how to do it exactly.
The reason is that browserSync requests all the data from the server for you, injects a little javascript listener and displays everything else:
<script type='text/javascript' id="__bs_script__">//<![CDATA[document.write("<script async src='/browser-sync/browser-sync-client.2.9.11.js'><\/script>".replace("HOST", location.hostname));//]]></script>
One way is to php artisan serve --host=0.0.0.0 in a separate terminal to start up the server and then use the .browserSync({proxy: 'localhost:8000'}). It all works - the BrowserSync UI and all the calls to refresh the pages.
Note: I could not connect to artisan serve without the --host=0.0.0.0.
For those wanting an all automated solution via gulp, here it is:
Use the gulp packages gulp-connect-php and laravel-elixir-browsersync2. The first starts up the php artisan serve and the other connects it to browserSync.
Install the packages:
npm install laravel-elixir-browsersync2 --save-dev
npm install gulp-connect-php --save-dev
Add the required lines to your gulpfile.js:
Code:
var elixir = require('laravel-elixir'),
gulp = require('gulp');
var connectPHP = require('gulp-connect-php');
var BrowserSync = require('laravel-elixir-browsersync2');
elixir(function(mix) {
mix.sass('app.scss');
});
elixir(function(mix) {
connectPHP.server({
base: './public',
hostname: '0.0.0.0',
port: 8000
});
BrowserSync.init();
mix.BrowserSync(
{
proxy: 'localhost:8000',
logPrefix : "Laravel Eixir BrowserSync",
logConnections : false,
reloadOnRestart : false,
notify : false
});
});
Then - simply gulp.
Disclaimer: This might not work with the gulp watch, but there might be people with the answer to that.
There is also a line PHP server not started. Retrying... before the [Laravel Eixir BrowserSync] Proxying: http://localhost:8000. It belongs to gulp-connect-php when trying to check if the server is running.
I found other solution on laracast for Bloomanity and it works with me like a charm!
$ php artisan serve --host=0
and then in your gulp add:
mix.browserSync({proxy: 'localhost:8000'});
I had to redownload all of my dev tools after upgrading/reset on Windows 10. I can't seem to get my server working with gulp-connect-php, gulp-browser-sync, and http-proxy. The task (below) is actually from this answer: Gulp-webapp running BrowserSync and PHP.
This is on top of a generation of gulp-webapp from Yeoman. The regular "serve" works, but of course doesn't spin up PHP files. I had it working before the upgrade, but now the http-proxy errors out with an ECONNREFUSED when I try to bring up the URL. Note that it doesn't error out until I actually go to the URL, if the task is setup to not open the browser automatically, it won't error until I go to localhost:3000.
Any ideas the cause of this error?
Gulp Task
gulp.task('php-serve', ['styles', 'fonts'], () => {
phpConnect.server({
port: 9001,
base: 'app',
open: false
});
const proxy = httpProxy.createProxyServer({});
browserSync({
notify: false,
open: false,
port: 9000,
server: {
baseDir: ['.tmp', 'app'],
routes: {
'/bower_components': 'bower_components'
},
middleware: function (req, res, next) {
var url = req.url;
if (!url.match(/^\/(styles|fonts|bower_components)\//)) {
proxy.web(req, res, { target: 'http://127.0.0.1:9001' });
}
else {
next();
}
}
}
});
gulp.watch([
'app/*.html',
'app/*.php',
'app/scripts/**/*.js',
'app/images/**/*',
'.tmp/fonts/**/*'
]).on('change', reload);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/fonts/**/*', ['fonts']);
gulp.watch('bower.json', ['wiredep', 'fonts']);
});
Gulp Run Task with Error
$ gulp php-serve
[07:30:09] Requiring external module babel-core/register
[07:30:11] Using gulpfile ~\...\gulpfile.babel.js
[07:30:11] Starting 'styles'...
[07:30:12] Starting 'fonts'...
[07:30:12] Finished 'styles' after 1.08 s
[07:30:12] Finished 'fonts' after 306 ms
[07:30:12] Starting 'php-serve'...
[07:30:12] Finished 'php-serve' after 183 ms
[BS] Access URLs:
----------------------------------
Local: http://localhost:9000
External: http://x.x.x.x:9000
----------------------------------
UI: http://localhost:3001
UI External: http://x.x.x.x:3001
----------------------------------
[BS] Serving files from: .tmp
[BS] Serving files from: app
C:\...\node_modules\http-proxy\lib\http-proxy\index.js:119
throw err;
^
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
I think I know the reason.
Check or you have php installed on your machine and added to your path variables.
open your command line and type:
$ php --version
If it returns:
sh.exe": php: command not found
It means it is not installed or not in the path variable.
You can install php by simply installing WAMP/XAMP or MAMP
https://www.apachefriends.org/index.html
To make sure it is in your path I like to use patheditor
https://patheditor2.codeplex.com/
There go through these simple steps
1) open Path Editor
2) click 'add' in the 'user' section
3) search the folder where php.exe is. (usually something like: C:/xampp/php)
4) click 'ok' and 'ok' again to close path editor
5) reopen your commandline tool and you will see that $ php --version will find the php.exe
Try to run your gulp task again. It should work!
There was a bad install of http-proxy and/or gulp-php-connect. I uninstalled them, cleared npm cache, and did a fresh install. Everything worked fine after that.
I am trying to use/run Google Web-Starter-Kit with PHP code and surfing through internet I found gulp-connect-php which helps to run PHP files inside gulp server(we can connect gulp with our local php service). So that i installed gulp-connect-php and added the following code to gulpfile.js
code:
var connect = require('gulp-connect-php');
gulp.task('connect', function() {
connect.server({
hostname: '0.0.0.0',
bin: 'C:/wamp/bin/php/php5.5.12/php.exe',
ini: 'C:/wamp/bin/php/php5.5.12/php.ini',
port: 8000,
base: 'dev'
});
});
gulp.task('default', ['connect']);
and entered the below command to execute gulp server with gulp-conntect
>gulp connect
but it throwing some ERROR with path i specified for PHP applicatoin.
ERROR:
E:\my-project>gulp connect
[10:51:57] Using gulpfile E:\my-project\gulpfile.js
[10:51:57] Starting 'connect'...
[10:51:57] Finished 'connect' after 12 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn C:/wamp/bin/php/php5.5.12/php.exe ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
I don't know where the issue lies on. please help on this.
An ENOENT error usually indicates that a file or directory is missing. Seeing that you are on windows, this would most likely be due to a wrong direction of slashes.
Try
bin: 'C:\\wamp\\bin\\php\\php5.5.12\\php.exe'
(same for ini) and make sure this file really exists! Other than that, if you can call php directly from your command line, you shouldn't need to point to the EXE file at all.