Laravel Mix 6 ver upgrade error inpackage.json - node.js

My task is to upgrade package.json in Laravel. I haven't had any problems using Laravel-Mix 5 ver until now, but I got the following error after switching to 6 ver.
error: unknown option '--env.mixfile=webpack.admin.mix' error Command
failed with exit code 1. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command. error: unknown option '--env.mixfile=webpack.client.mix'
error Command failed with exit code 1. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command.
Perhaps the way "Scripts" is written may have changed. My Scripts in Package.json as below. Webpack.mix.js is divided by authority.
"scripts": {
"dev": "yarn run-p dev:admin dev:client dev:sp",
"dev:admin": "NODE_ENV=local yarn development -- --env.mixfile=webpack.admin.mix",
"dev:client": "NODE_ENV=local yarn development -- --env.mixfile=webpack.client.mix",
"dev:sp": "NODE_ENV=local yarn development -- --env.mixfile=webpack.sp.mix",
...
My env
PHP: 7.4.29
Laravel :8.76.2
Yarn: 1.22.5
Node: 16.14.2
Laravel Mix: 6.0.43
Already tried
Remake node_modules.
Yarn cache clear.
Deleted "-- --" in Scripts then try again.

What does the development script run?
In a default laravel mix package.json its mix. If that's the case you could try the following:
"scripts": {
"dev": "yarn run-p dev:admin dev:client dev:sp",
"dev:admin": "mix --mix-config=webpack.admin.mix.js",
"dev:client": "mix --mix-config=webpack.client.mix.js",
"dev:sp": "mix --mix-config=webpack.sp.mix.js",
...

Related

Yarn "posttest" script does not work if "test" script fails

Well, I have these scripts in my package.json for testing some code in NodeJS.
"scripts": {
"pretest": "env NODE_ENV=test sequelize db:migrate",
"test": "jest",
"posttest": "env NODE_ENV=test sequelize db:migrate:undo:all"
}
When the tests go clear, the "posttest" runs, but when the tests fail, I receive a
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
in VS Code. There is nothing usefull on the link about the problem, neither on the internet.
So I found this link about NPM:
https://github.com/npm/npm/issues/5493
The guy said:
In the vast majority of cases, users are going to be unpleasantly
surprised if posttest runs after test failures (you don't want your
test environment being cleaned up or new versions being published if
there were test failures, for instance). As such, this behavior isn't
going to change. Putting something like "test":"npm run-script
test-failing || npm run-script mandatory-cleanup" into your
package.json will give you what you want.
This did not solve my problem. With more research I found this:
npm posttest doesn't trigger if npm test fails
The solutions did not work for me either.
So how can I run the "posttest" script even if the tests fail?
Well, with the conversation above, I got to this solution:
This is my scripts in package.json:
"scripts": {
"dev": "nodemon src/server.js",
"pretest": "env NODE_ENV=test sequelize db:migrate",
"run-tests": "jest",
"run-after-tests": "env NODE_ENV=test sequelize db:migrate:undo:all",
"test": "npm-run-all run-tests run-after-tests --continue-on-error"
},
I installed the npm-run-all package and it runs the run-after-test script even if the tests fail. Now I get the errors
error Command failed with exit code 1.
from the test script, and
ERROR: "test" exited with 1.
error Command failed with exit code 1.
from run-after-test, but in the end my problem got solved. If someone has a better solution with no errors at the end of the scripts, please share with us.

Start-server-and-test "server closed unexpectedly"

I'm using the start-server-and-test package to start a server on my Azure pipeline to run Cypress.
This is the yarn command I use to start everything: yarn cy:build:workspace
"cy:build:workspace": "yarn cy:clean && start-server-and-test start http://localhost:8080 cy:run:workspace"
I'm running NODE_VERSION: "12.10.0" on the Azure env.
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "d:\a\_temp\ce28689e-eef6-4eeb-bad2-82310f748e1b.cmd""
yarn run v1.22.4
$ yarn cy:clean && start-server-and-test start http://localhost:3000 cy:run:workspace
$ rimraf cypress/reports/*
1: starting server using command "npm run start"
and when url "[ 'http://localhost:3000' ]" is responding with HTTP status code 200
running tests using command "npm run cy:run:workspace"
> #someProjectsbs/suite-packages#0.1.1 start D:\a\1\s
> lerna exec --scope=#someProjectsbs/suite -- yarn start --all-apps
lerna notice cli v3.20.2
lerna info ci enabled
lerna notice filter including "#someProjectsbs/suite"
lerna info filter [ '#someProjectsbs/suite' ]
lerna info Executing command in 1 package: "yarn start --all-apps"
$ cross-env react-app-rewired start --extended-linting --all-apps
[]
[info] [webpackbar] Compiling #someProjectsbs/suite
(node:4672) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
i 「wds」: Project is running at http://192.168.0.100/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from D:\a\1\s\packages\app\suite\public
i 「wds」: 404s will fallback to /
Starting the development server...
lerna success exec Executed command in 1 package: "yarn start --all-apps"
Error: server closed unexpectedly
at ChildProcess.onClose (D:\a\1\s\node_modules\start-server-and-test\src\index.js:69:14)
at ChildProcess.emit (events.js:209:13)
at ChildProcess.cp.emit (D:\a\1\s\node_modules\start-server-and-test\node_modules\cross-spawn\lib\enoent.js:34:29)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
##[error]Cmd.exe exited with code '1'.
Finishing: Run Cypress testsk
Locally I have everything running, any suggestions why the server stops on the Azure environment?
Check your package.json, if you are using "react-scripts": "3.4.1" downgrade to 3.4.0
Also verify this link to use start-server-and-test with yarn, you need to add like strings some yarn commands https://github.com/bahmutov/start-server-and-test#note-for-yarn-users
Set the CI environment variable to true. Source: https://github.com/facebook/create-react-app/issues/8688#issuecomment-642309787
I had the same issue, but moving to wait-on solve the issue to me
https://docs.cypress.io/guides/guides/continuous-integration.html#Boot-your-server

Next.js - ERROR Build directory is not writeable on EC2

I'm running for the first time my Next.js app with a custom server.js on Elastic BeanStalk with 64bit Amazon Linux/4.11.0.
After the creation on the application, the environment and the deploy with the eb-cli I received a warning into the EB dashboard Environment health has transitioned from Degraded to Severe.
I changed the Node command into the config to npm run deploy. Nothing changed.
Here's my package.json.
"scripts": {
"start": "pm2 start server.js -i max",
"build": "next build",
"dev": "nodemon --exec babel-node server.js",
"start-next": "next start",
"deploy": "NODE_ENV=production next build && pm2 start server.js -i max",
"test": "echo \"Error: no test specified\" && exit 1"
},
I connected to the eb instance with eb ssh and after I've located the project dir I tried to execute npm run build but an error happened.
> NODE_ENV=production next build && pm2 start server.js -i max
> Build error occurred
Error: > Build directory is not writeable. https://err.sh/zeit/next.js/build-dir-not-writeable
at build (/var/app/current/node_modules/next/dist/build/index.js:1:6361)
at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webreader-client#1.0.0 deploy: `NODE_ENV=production next build && pm2 start server.js -i max`
npm ERR! Exit status 1
I've created a .next directory with sudo but the error is still raised.
Docs:
https://github.com/zeit/next.js/blob/master/errors/build-dir-not-writeable.md
After spending nearly 4 hours on the phone with AWS support, their solution was as follows:
create a folder/file in the root of your project: .ebextensions/00_dir_permission.config
commands:
01_set_file_permissions:
command: "chmod 777 -R /tmp"
Of course this is less than ideal, but for some reason right now in EB permissions have changed such that you are not able to kick off the build without tweaking on permissions like this. Hoping this changes soon.
I was getting this same error locally and after about an hour of troubleshooting, I realized I had my node version set wrong. Seems like next 9.4 doesn't support version 9 of node. I updated to version 12 and it's working without issue.

with grapejs - did "npm start", but localhost:8080 will say This site can’t be reached localhost refused to connect

I downloaded the zip (from https://github.com/artf/grapesjs) and unzipped, then did the "npm i" command. That tooks a while, then I ran "npm start" and the console displayed this:
e:\GitHub\NealWalters\GrapeJSDemo>npm start
grapesjs#0.14.5 start e:\GitHub\NealWalters\GrapeJSDemo
npm run build:css -- -w & webpack-dev-server --open --progress --colors
grapesjs#0.14.5 build:css e:\GitHub\NealWalters\GrapeJSDemo
node-sass src/styles/scss/main.scss dist/css/grapes.min.css --output-style compressed "-w"
When I try http://localhost:8080 in the browser, I get the error:
This site can’t be reached
localhost refused to connect.
Here is my directory structure:
I have run other NodeJS programs before with success. Running on Windows 10.
On npm start, the process gets bound to watching files and doesn't reach the next command to startup the server. Try adding start in the beginning of the start script to run a separate process for watching the files. Then the command to startup the server will get executed.
So in package.json, change the start script to the following:
{
...
"scripts": {
...
"start": "start npm run build:css -- -w & webpack-dev-server --open --progress --colors"
}

How to deploy an npm project to Heroku?

I currently have an npm project built with vue-cli and socket.io server.
This is how my project is structured:
Project/
|--node_server/
| |--server.js
|--src/
| |--main.js
| |--App.vue
| |--other .vue files and folders
I do not know how to deploy this app on Heroku because I will need to run two scripts while deploying that is node server.js (in the node_server folder) and npm run build or npm run dev (in the root folder).
What are the steps on how to deploy it successfully? Heroku takes my project from github whenever I push and builds it automatically. I have tried deploying but it ends up with an error page.
Let's say you need to build the front-end with build script first, and then you need to run nodejs server with start script which is node server.js.
...
"scripts": {
"build": "gulp or something idk"
"prestart": "npm run build",
"start": "node node_server/server.js",
},
...
But if you need to run these two scripts at the same time you can achieve this with something like that:
...
"scripts": {
"build": "gulp or something idk"
"start": "npm run build & node node_server/server.js",
},
...
I hope it would be helpful.
For an example, you can take a look at the package.json of one of my project: https://github.com/hisener/pirate-radio/blob/master/package.json
For more information, please refer https://docs.npmjs.com/misc/scripts

Resources