I was trying to deploy my reactjs rails app on heroku.
Everything seems okay until I get this error:
Module build failed (from ./node_modules/babel-loader/lib/index.js):
remote: Error: Cannot find module '#babel/preset-react'
The app works fine in my localhost. I tried deleting my node_modules folder then running npm install but the error persisted(only when deploying at heroku).
My package.json:
{
"name": "App",
"private": true,
"dependencies": {
"#rails/webpacker": "5.4.0",
"#types/react": "^17.0.18",
"#types/react-dom": "^17.0.9",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react_ujs": "^2.6.1",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"devDependencies": {
"#babel/plugin-syntax-jsx": "^7.14.5",
"#babel/plugin-transform-react-jsx": "^7.14.9",
"#babel/preset-env": "^7.15.0",
"#babel/preset-react": "^7.14.5",
"webpack-dev-server": "^3.11.2"
}
}
I managed to deploy it. I based my answer here: Why is devDependencies' pruning skipped even if NPM_CONFIG_PRODUCTION is true?
What I did was set:
NPM_CONFIG_PRODUCTION= false
YARN_PRODUCTION = false
YARN_CONFIG_PRODUCTION = false
I tested changing ENV values and this what worked for me.
This can set at heroku settings under config vars
Heroku defaults to NODE_END=production. How does this affect your build?
You have #babel/preset-react in devDependencies. When you do npm i (or yarn) to install packages with NODE_ENV=production, npm (or yarn) only installs dependencies (it wont install devDependencies).
To get around this, you can -
either override NODE_ENV. ($ NODE_ENV=development npm i)
Run npm i --only=dev before you build
To be on the safe side, revert the value on NODE_ENV to production when you run in production environment (Heroku in your case).
Related
I have the following package.json for my React project
{
"name": "webforms-react-sample",
"version": "1.0.0",
"description": "Sample projects for hosting React apps in a WebForms application.",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --config webpack.dev.js",
"build-dev": "npx webpack --config webpack.dev.js",
"build-prod": "npx webpack --config webpack.prod.js"
},
"author": "Dimitris Vardalis",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.1.0",
"#babel/core": "^7.1.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^6.7.3",
"react": "17.0.2",
"react-dom": "17.0.2",
"style-loader": "^0.23.0",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"react-hot-loader": "^4.6.5",
"react-router-dom": "^5.2.0"
}
}
I'm trying to run the build-dev script. When trying locally I can make that script to work as is expected so build is made. But when going to the build pipeline is returning me this:
npm WARN exec The following package was not found and will be installed: webpack#5.75.0
CLI for webpack must be installed.
> webforms-react-sample#1.0.0 build-dev
webpack-cli (https://github.com/webpack/webpack-cli)
We will use "npm" to install the CLI via "npm install -D webpack-cli".
> npx webpack --config webpack.dev.js
Do you want to install 'webpack-cli' (yes/no):
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
I'm using Azure Devops and a windows machine agent (always using the latest version) for running the pipeline. And yes I'm installing npm packages before the step when trying to run that script. I don't have any npm cache step to avoid Azure caching old files and not updating on releases (this happened to me on other pipelines).
Current pipeline is this (see pictures)
pipeline steps part 1
Pipeline steps part2
I have already tried uninstalling the packages and reinstalling them, same results and been breaking my head for a while and still the same results.
Well I made it work by changing npm install step on React to npm install --force.
I'm trying to my deploy a small blog built with NextJS on Netlify but I'm getting this error while generating a build:
10:59:39 PM: [1/5] Validating package.json...
10:59:39 PM: error my-app-name#0.1.0: The engine "node" is incompatible with this module. Expected version "12.18.3". Got "12.18.0"
10:59:39 PM: error Found incompatible module.
My package.json has dependencies and engines specified like this:
"dependencies": {
"autoprefixer": "^10.0.4",
"next": "^10.0.0",
"postcss": "^8.1.10",
"react": "16.13.1",
"react-dom": "16.13.1",
"tailwindcss": "^2.0.1"
},
"engines": {
"node": "12.18.3"
}
However, if I change my node version in package.json to 12.18.0 it seems to generate the build on netlify successfully, but in that case my local dev server has trouble starting.
I solved this with yarn config set ignore-engines true and then delete node-modules and reinstall. But its a hack.
When I install redux-thunk it shows an error and you can see attached image for more info -
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Users\siddharth.vyas\Desktop\react-native_Proj\AwesomeProject\node_modules.staging\redux-thunk-069b38d0' -> 'C:\Users\siddharth.vyas\Desktop\react-native_Proj\AwesomeProject\node_modules\redux-thunk'
And I have also try to install "redux-thunk" with the administrator but shows the same error.
Pakage.json -
"dependencies": {
"axios": "^0.19.0",
"react": "16.8.3",
"react-native": "0.59.9",
"react-native-loading-spinner-overlay": "^1.0.1",
"react-redux": "^7.1.0",
"redux": "^4.0.1",
"redux-axios-middleware": "^4.0.0"
},
"devDependencies": {
"#babel/core": "7.4.5",
"#babel/runtime": "7.4.5",
"babel-jest": "24.8.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.3"
},
try removing node_modules and do npm install. If it doesn't work, delete node_modules, add "redux-thunk": "^2.3.0" to your dependencies, then run npm install -i
I have faced similar issues in windows. this looks more of a permission issue.
Try running the cmd window in run as administrator mode. this should mostly give permission to npm to execute the script.
if that does not work, then the option would be to delete the folder redux-thunk from node_modules directory and try reinstalling the redux-thunk module again
I am assuming I should be able to deploy my reactJS to an S3 instance on AWS but I do not know how to do this. I found publish-react-app on github and I am trying to follow those steps. When I execute npm run build I get this error stream:
c:\jrs\PM_01\React>npm run build
npm ERR! missing script: build
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\jonat\AppData\Roaming\npm-cache\_logs\2018-09-05T18_57_19_811Z-debug.log
c:\jrs\PM_01\React>npm run build
> sample-app#1.0.0 build c:\jrs\PM_01\React
> react-scripts build
'react-scripts' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sample-app#1.0.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sample-app#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\jonat\AppData\Roaming\npm-cache\_logs\2018-09-05T19_06_24_048Z-debug.log
I have no idea what I need to put into the scrips section of my package.json file. This is what my package.json file looks like:
{
"name": "sample-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --open"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"css-loader": "^1.0.0",
"style-loader": "^0.21.0",
"webpack": "^2.6.1",
"webpack-dev-server": "^2.4.5"
},
"dependencies": {
"cors": "^2.8.4",
"ebay-node-api": "^2.2.1",
"moment": "^2.20.1",
"moment-timezone": "^0.5.14",
"publish-react-app": "^1.0.1",
"react": "^15.6.2",
"react-barcode": "^1.3.4",
"react-dom": "^15.6.2",
"react-moment": "^0.7.0",
"react-redux": "^5.0.5",
"react-router-dom": "^4.1.1",
"redux": "^3.7.0",
"reselect": "^3.0.1",
"simple-flexbox": "^1.2.0"
},
"babel": {
"presets": [
[
"es2015",
{
"modules": false
}
],
"stage-2",
"react"
]
}
}
I created a free tier S3 on AWS and created a user and a bucket but I really dont know what else to do in order to get my application deployed.
Thanks.
Your package.json is missing the key build. Generally with tools such as create-react-app it comes with a build script to prepare assets for production. As for hosting, Heroku is pretty easy to get up and running quickly.
The template being considered is https://github.com/StephenGrider/ReduxSimpleStarter
After git clone, the folder is merely 160kb.
But after npm install, the folder is 620MB.
Is there a way to make it as small as possible? It was suspected that the react native stuff (including the binaries?) is really huge, so can something be done such as npm install --minus react-native if react native is not needed at all?
P.S. a few days have passed, and today Apr 2, 2017, the same repo, the same as before, after npm install, is only 138MB. I guess somebody fixed the dependencies (of the npm modules registry), so that some 500MB of stuff is not installed.
There is no react-native in the starter project that you referenced. :)
So, that is not what is causing the large directory.
It is typical to have a large node_modules directory. This directory is usually placed in the .gitignore (or similar) so that it is not committed to the source control repository.
In order to track dependencies, use the --save and --save-dev switches in npm install and make sure to commit your package.json
Also, when you npm install for production, use the npm install --production switch to exclude dev dependencies.
When you run npm install all dependencies will be installed as from package.json,
this includes devDependencies and dependencies (using npm you can also control what to install or not as Davin Tryon pointed out). Below an extract from your package.json you can see all dep included. Also you could consider ignoring node_modules on git or svn to do use space on your repository.
You could consider manually remove the node_modules directory if you do not work on a project so you can save some space on you HD.
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"jquery": "^2.2.1",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"lodash": "^3.10.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "^4.0.0",
"react-router": "^2.0.1",
"redux": "^3.0.4"
}