I've encountered a slight problem. I know that I can build react-app using npm run build and it will create optimized build folder which I can load to production. But some days ago I started to use node.js with my react application. I am confused now - how should I build such an app now?
My folders structure:
my-app-|
|-client-|
| |-package.json // root react package file
|
|
|- server.js // node.js (express) root file
|- package.json // root node package file
EDIT 1
> server#1.0.0 build C:\Users\Horseman.mini\PhpstormProjects\landing
> npm run build && cd ./client && npm run build
> server#1.0.0 build C:\Users\Horseman.mini\PhpstormProjects\landing
> npm run build && cd ./client && npm run build
> server#1.0.0 build C:\Users\Horseman.mini\PhpstormProjects\landing
> npm run build && cd ./client && npm run build
> server#1.0.0 build C:\Users\Horseman.mini\PhpstormProjects\landing
> npm run build && cd ./client && npm run build
'npm' is not recognized as internal or external command, operable program or batch file
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server#1.0.0 build: `npm run build && cd ./client && npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Horseman.mini\AppData\Roaming\npm-cache\_logs\2021-02-22T14_49_23_308Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server#1.0.0 build: `npm run build && cd ./client && npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Horseman.mini\AppData\Roaming\npm-cache\_logs\2021-02-22T14_49_23_345Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server#1.0.0 build: `npm run build && cd ./client && npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
PS npm --version returns 6.14.10
If I go to client folder and build it will build, but without server side
You can now delegate the responsibility of serving your frontend build folder to the server.js i.e the server only. The simplest thing could be using express.static to serve the frontend like so :-
app.use(express.static(path.join(__dirname, "./dist"))); where app is the instance of your express server.
where ./dist is the relative path to your root folder so something like my-app/dist where you place your build files. Again it's totally upto you what name you want to use. Essentially all the static files i.e js,css and html will be part of this dist folder and will be served to the user when he/she hits the base path. Since both frontend and backend would be available from the same server, there would not be any need to handle CORS scenarios as well unless well it's absolutely required by your implementation.
Using parent folder with package.json and put your respective build commands in that.
my-app-|
|-client-|
| |-package.json // root react package file
|
|
|- server.js // node.js (express) root file
|- package.json // root node package file ---> add build command for front and back here.
Your root package.json can have following command.
{
"build": "npm run build && cd ./client && npm run build"
}
This will build your backend first and then frontend, if you want both command to run simultaneously then you can use package like concurrently.
Related
started installing plugins to my Laravel project.
Laravel new public
npm install
composer require laravel / ui
php artisan ui vue
npm install -D tailwindcss # latest postcss # latest autoprefixer # latest
npx tailwindcss init
add line in tailwind.config.js purge: [ './resources//*.blade.php', './resources//.js',
'./resources/**/.vue', ],
add line in webpack.mix.js require ("tailwindcss"),
Add im resource / css / app.css 3-line #tailwind base; #tailwind components; #tailwind utilities;
add link stylesheet in main template file (main.blade.php) {{asset ('css / app.css')}}
After all the monipulations mentioned above, I execute the command npm install && npm run dev, and I get an error
> npm run development
> # development D:\laravel\public
> mix
× Mix
Compiled with some errors in 6.30s
ERROR in ./resources/js/components/ExampleComponent.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
| <div>
| <h3>Hey</h3>
webpack compiled with 1 error
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # development: `mix`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\****\AppData\Roaming\npm-cache\_logs\2021-02-26T09_06_38_033Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\***\AppData\Roaming\npm-cache\_logs\2021-02-26T09_06_38_066Z-debug.log
Would you try these two solutions
1 - Run MacOS Or Windows super user
1.1 MacOS sudo npm run development
1.2 Windows right click terminal open with Administrator
2- Cleen code to
I am trying to get a site to deploy to Firebase using TravisCI. I keep running into an issue when the functions deploy and try to run lint. eslint doesn't seem to be there, even though I added a command to cd and npm install. I'm sure this is some kind of no-brainer. What am I missing?
Here's my .travis.yml:
language: node_js
node_js:
- 12
deploy:
provider: firebase
project: "*****"
message: "Deployed from Github by TravisCI"
token:
secure:
*******
env:
global:
secure:
*****
branches:
only:
- master
before_deploy:
- npm install -g gatsby-cli
- rm -rf node_modules/*/.git/
- npm install
- gatsby build
- cd functions && npm install --dev && cd ..
Here's the error in the Travis log:
Installing deploy dependencies
dpl.2
Preparing deploy
dpl.3
Deploying application
=== Deploying to 'covid19-reports'...
i deploying storage, firestore, functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint /home/travis/build/amygroshek/covid19reports/functions
> eslint .
sh: 1: eslint: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! functions# lint: `eslint .`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/travis/.npm/_logs/2020-03-23T00_34_17_951Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
In my project, I use Parcel to bundle everything. Now, I am at the point where I need to deploy my app.
I clone my git repo with my React app and I put in the Node server.
I tried every command possible to install parcel, but I always get the following error :
> pp-react#0.1.0 build /home/volodymk/react
> parcel build index.html
sh: parcel: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! pp-react#0.1.0 build: `parcel build index.html`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the pp-react#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/volodymk/.npm/_logs/2020-01-12T19_26_22_634Z-debug.log
How can I fix this ?
To run any installed node package (not just Parcel), use npx, the utility command shipped with npm. It executes packages that come with a runtime command in your node_modules/packagename/.bin directories.
As in npx parcel build index.html
More information available in the npx readme.
Im trying to set up continuous deployment on Netlify. Ive linked my Github account so I now need to set my build command:
The complication is that my package.json with the build command (from create-react-app) is not in the project root. Instead its 1 folder deep like so:
react // this is a folder
-package.json // has build commands for React
server // this is a folder
-package.json // has build commands for my backend as a service
As I'm using a backend as a service I don't need anything in the 'server' folder deployed to Netlify, just the contence of the 'react' folder.
Can I run a command in react/package.json from the project root?
On my local machine I can run the build command from the root with this:
{
"scripts": {
"netlify": "cd ./react && npm run build"
}
}
But on Netlify it errors:
9:56:31 AM: Executing user command: npm run netlify
9:56:31 AM: > # netlify /opt/build/repo
9:56:31 AM: > cd ./react && npm run build
9:56:32 AM: > testproject#0.0.1 build /opt/build/repo/react
9:56:32 AM: > npm-run-all build-css build-js
9:56:32 AM: sh: 1: npm-run-all: not found
9:56:32 AM: npm ERR! file sh
9:56:32 AM: npm ERR! code ELIFECYCLE
9:56:32 AM: npm ERR! errno ENOENT
9:56:32 AM: npm ERR! syscall spawn
9:56:32 AM: npm ERR! testproject#0.0.1 build: `npm-run-all build-css build-js`
9:56:32 AM: npm ERR! spawn ENOENT
9:56:32 AM: npm ERR!
9:56:32 AM: npm ERR! Failed at the testproject#0.0.1 build script.
9:56:32 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
9:56:32 AM: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
9:56:32 AM: npm ERR! A complete log of this run can be found in:
9:56:32 AM: npm ERR! /opt/buildhome/.npm/_logs/2018-03-01T02_56_32_022Z-debug.log
9:56:32 AM: npm ERR! code ELIFECYCLE
9:56:32 AM: npm ERR! errno 1
9:56:32 AM: npm ERR! # netlify: `cd ./react && npm run build`
9:56:32 AM: npm ERR! Exit status 1
disclaimer: I work for Netlify
Our build process will only 'npm install' for you if there is a /package.json. I think you could probably get a successful build with this build command:
cd ./react && npm install && npm run build
...assuming you have npm-run-all in package.json anyway :)
This however is not the BEST way to solve the problem. The best practice would be to instead use the netlify.toml file to set a base for your build. We'll cd to this directory before starting the build, and then we'll just pick up your package.json and do the installation automatically so your build command would be simplified to npm run build, and anyone else who clones your repo would also be set up for success on Netlify :)
[build]
base = "react"
...is all that you'd need in that file.
After npm run deploy i have errors like above
Repo on Github
I am trying to deploy my react-app on gh-pages on Github (create-react-app)
'gh-pages' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-world-4#0.1.0 deploy: `npm run build&&gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello-world-4#0.1.0 deploy script 'npm run build&&gh-page
s -d build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the hello-world-4 package
,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run build&&gh-pages -d build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs hello-world-4
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls hello-world-4
npm ERR! There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\jan\AppData\Roaming\npm-cache\_logs\2017-05-12T17_55_00_56
9Z-debug.log
So I run this command npm install --save gh-pages
like below
After that I run the command npm run deploy
My code published successfully like below.
For more details just follow this link by Facebook which is given below.
(https://facebook.github.io/create-react-app/docs/deployment#github-pages-https-pagesgithubcom)
I hope your issue will be resolved. In case of error please reply.
please install gh-pages and it ready to go
To install
npm install gh-pages
to deploy
add this to package.json
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
and then this
npm run deploy
gh pages stands for GitHub Pages. It is simply a way to deploy a website via a github repo. Basically, NPM is yelling because when it attempts to run the command deploy, there is not link or reference to the line
$npm run build&&gh-pages -d build
You need make sure that gh-pages -d build is defined. A place to start would be running gh-pages --man or gh-pages --help
I facing the same problem I do the following command before
git push
not working. After
git push
I do the same command it works correctly.
npm install gh-pages
and deploy
npm run deploy