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.
Related
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.
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.
I've been going through the nightmare that is trying to get lerna to publish in my ci pipeline.
I've managed to have the scripts pull from git to check tags and I've found the withNPM pipeline plugin. Because I'm using lerna to publish multiple packages I have to move the .npmrc file that the plugin creates in the workspace to the root of the the home directory so that all packages can access it.
The NPM plugin uses the jenkins config file to create the .npmrc file. Which looks like this:
//registry.npmjs.com/:_authToken=TOKEN
Here is what I have in my Jenkins pipeline.
stage('lerna publish') {
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'cb8acd82-3a50-4a94-9d5f-44b04856e6fd', keyFileVariable: 'GITHUB_KEY')]) {
sh 'echo ssh -i $GITHUB_KEY -l git -o StrictHostKeyChecking=no \\"\\$#\\" > ./run_ssh.sh'
sh 'chmod +x ./run_ssh.sh'
withEnv(['GIT_SSH=./run_ssh.sh']) {
withNPM(npmrcConfig: 'da4e5199-b04b-41b6-a03f-dfbcc344f701') {
sh "rm -rf ~/.npmrc"
sh 'mv ./.npmrc ~/.npmrc'
sh 'npm config set registry https://registry.npmjs.com/'
sh 'git config --global user.email "thomas#reggi.com"'
sh 'git config --global user.name "reggi"'
sh 'git checkout master'
sh 'git pull origin master --force'
sh 'npm run lerna-publish'
}
}
}
}
}
Here's the error:
lerna info auto-confirmed
lerna info publish Publishing packages to npm...
lerna ERR! npm publish --ignore-scripts exited 1 in '#reggi/help.filter-until'
lerna ERR! npm publish --ignore-scripts stderr:
npm notice
npm notice package: #reggi/help.filter-until#0.0.20
npm notice === Tarball Contents ===
npm notice 1.5kB package.json
npm notice 609B index.build.js
npm notice === Tarball Details ===
npm notice name: #reggi/help.filter-until
npm notice version: 0.0.20
npm notice package size: 997 B
npm notice unpacked size: 2.1 kB
npm notice shasum: a6db6d4dc02f05548c22fe2e034832ac02252633
npm notice integrity: sha512-6oAFaXqZMREsh[...]GnMcnIxXUBINg==
npm notice total files: 2
npm notice
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
I found I wasn't being consistent with the urls above and changed them both to .com and now I'm getting this issue:
lerna info auto-confirmed
lerna info publish Publishing packages to npm...
lerna ERR! npm publish --ignore-scripts exited 1 in '#reggi/help.filter-until'
lerna ERR! npm publish --ignore-scripts stderr:
npm notice
npm notice package: #reggi/help.filter-until#0.0.23
npm notice === Tarball Contents ===
npm notice 1.5kB package.json
npm notice 609B index.build.js
npm notice === Tarball Details ===
npm notice name: #reggi/help.filter-until
npm notice version: 0.0.23
npm notice package size: 1.0 kB
npm notice unpacked size: 2.1 kB
npm notice shasum: 60ee325b219abdae06a75cfe45bc66096f715187
npm notice integrity: sha512-o4ahyOWAsUk3j[...]O/3MH2Tpv1tOQ==
npm notice total files: 2
npm notice
npm ERR! publish Failed PUT 404
npm ERR! code E404
npm ERR! 404 Not found : #reggi/help.filter-until
npm ERR! 404
npm ERR! 404 '#reggi/help.filter-until' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
I have the token setting using the .org domain and the registry set to the .com domain. :(
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