I am trying to set up my "web app" on Heroku. When I double click on my index.html it shows up in my browser but the app fails to open in Heroku. I am accessing my files through github, which is working fine.
In oder to set up my working environment I followed this tutorial exactly:
https://www.kirupa.com/react/setting_up_react_environment.htm
After reading about my initial errors in Heroku:
1.) I added the Node Version (But not the npm Version since I only saw how to add one or the other and not both.)
"engines": {
"node": "7.10.0"},
2.) I changed the Script to:
"scripts": {
"start": "node index.js"},
That was straight forward enough, but now after running npm start, I see a distinct error (also reflected in the https://www.npmjs.com browser test):
Error: Cannot find module '/Users/MyUser/MyFolder/index.js'
Now, due to that tutorial above, I only have "index.jsx" located within an additional folder like: MyFolder/dev/index.jsx
I tried to change the file extension in package.json and or the file path, but no matter what I do, the file is not being found. I am guessing that ".jsx" should automatically be recognised as ".js", but I think that only because of the way that the tutorial was written...
Please help me figure out how to run npm start without error.
Thank you in advance!
I am no longer asking this question, although I am still curious about why it didn't work. I mostly just need a set up that WILL work. I am willing to start over from scratch...
I'm in the same boat here. In comparing a working version I had, adding a file called "Procfile" (no extension) then putting in:
web: node index.js
should work.
Read here for more info:
https://devcenter.heroku.com/articles/procfile
Hope it helps! Sorry it's like 7 months late eheh
Related
My setup in GCF:
install npm install --save puppeteer from project cloud shell
edit package.json like so:
{ "dependencies": { "puppeteer": "^19.2.2" } }
paste code from medium.com into index.js:
https://gist.githubusercontent.com/Alezco/b9b7ce4ec7ee7f208818e395225fcbbe/raw/8554acc8b311a10e272f5d1b98dce3400945bb00/index.js
deploy with 2 GB RAM, 0-3 instances, max 500s timeout
I get these errors after building or opening the URL:
Internal Server Error
Could not find Chromium (rev. 1056772). This can occur if either 1. you did not perform an installation before running the script (e.g. npm install) or 2. your cache path is incorrectly configured (which is: /workspace/.cache/puppeteer). For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
When I run npm list both webdriver and puppeteer are installed. I suspect there is an issue this Path but I cannot figure out where it should lead.
I could then provide puppeteer.launch() with argument executablePath which might solve the problem.
I tried reinstalling puppeteer and changing configuration. No luck.
In addition to adding a .puppeteerrc.cjs per Kristofer's answer, I added a postinstall script in my package.json:
"scripts": {
...
"postinstall": "node node_modules/puppeteer/install.js"
},
This fixed the problem and I was able to deploy my Google Cloud Function. This is a temporary fix until issue #9128 is fixed.
I had the exact same issue and it seems to be related to this https://github.com/puppeteer/puppeteer/issues/9128
I'm using Firebase and don't have complete control over the build process when I deploy my functions but I still have access to the build logs. From the issue above, I realized I needed to handle the cache directory and the NPM version for this to work.
As far as I can tell the problem is that the build step installs the Chrome browser needed for Puppeteer in a cache directory outside of the final image that is used for the actuall function. In that context the error message makes more sence, it can't find the browser therefor it doesn't work.
I was using Node 14 in my cloud functions which used NPM 6.14.17 in the build steps. According to the issue you need to use NPM > 7 so I upgraded my function to use Node 16.
Then I added the .puppeteerrc.cjs from https://pptr.dev/guides/configuration/#examples when testing that locally it will add a .cache directory where the Chrome installation is. This has to be ignored when deploying the cloud function or the deplot will fail due to size.
In the firebase.json add:
"functions": {
"ignore": [
".cache"
]
},
The last step is pretty specific for Firebase and I'm not sure how this applies to your build steps etc. But this solved my issue that had the exact same error messages as you had. So double check the following:
NPM version in the build step, needs to beat least v.7 - Node 16 should do this.
Cache directory specified in the .puppeteerrc.cjs
It also looks like your using an old Puppeteer version, I used 19.3
I got this same (very missleading) error in my Puppeteer project which I run in Google Cloud Function. The issue was that Function was finishing (exiting) before the async Puppeteer script was finished.
Resolved this issue by changing the "await browser.close();" to a Promise and creating the response message in promise.then().
... only to hit next problem. My script is not downloading the csv file as expected. Works locally though...
A beginner here. I started my journey into coding a couple of months ago and finally I have decided to set-up WSL2. I have successfully installed WSL2 together with NPM and Node.
I have created a test project to start playing with, where I have installed parcel-bundler as a local dependency using npm. The package.json file gets updated to include parcel-bundler, so all good up to here.
package.json file
However, when trying to start parcel, I get a message from my terminal saying that parcel command be found!
terminal parcel not working
I am pretty sure there is a little thing I am missing here, but have spent hours looking for an answer but havent been able to find anything.
Any advise would be greatly appreciated, and let me know if you need any more info from my side.
Cheers,
Alejandro
I have been following along this youtube playlist: https://www.youtube.com/watch?v=P3R-8jj3S7U. We got to the part where we finished a model and are ready to test. Run nodemoncommand to start the API and I get this error
Here is the file in question as well
Thanks for the help
UPDATE: In the package.json file i changed main to the exact file path of index.js you can see the package.json file here. This seemed to produce a better result but still didnt fix the issue. The error now reads clean - exit waiting for changes before restart and seems like it should be working but it isnt. I attached a sceengrab to have a better look. View Error
UPDATE #2: I changed the main property in the package.json file to app.js and ran nodemon command and produced this error. A bit of progress?
UPDATE #3: Here is my app.js file for reference
UPDATE #4: I updated my express property verision to include an actual verison number then ran npm install which seemed to be sucessful. I then ran nodemon again. Here are the results
Based on the information you've provided, I would guess you are executing nodemon by just typing the nodemon command without any arguments. This only works if your entry point is named index.js, but in the screenshot you provided it's clear that your entry point is named app.js, so you should be running nodemon with the following command:
nodemon app.js
I have a React project and I configured a build process in a file named build.js. The file tree is as below:
File structure:
I added "node build.js" script to scripts in package.json. It works fine on MacOS. However when I try to run the same npm run build script in my Windows machine, I get an error which says: "The system cannot find the file specified." "node build.js" command works fine when I move the file outside of project, for example to desktop. However, it does not work in the project.
The error from console:
I searched for any similar problem, but could not find anything. Any help would be appreciated.
edit: I solved my problem. It sees the file but can't see the file which should be removed by script. I misunderstood the problem and this is a false alarm. Sorry.
Receiving this warning on running a node.js app despite all testing suggesting everything fine.
I've included the below code in my app to fault find:
console.log('NODE_ENV: ' + config.util.getEnv('NODE_ENV'));
console.log('NODE_CONFIG_DIR: ' + config.util.getEnv('NODE_CONFIG_DIR'));
And the output in terminal is:
NODE_ENV: test
NODE_CONFIG_DIR: C:\Users\[username]\OneDrive - [Company Name]\Documents\projects\[project name]\server\config
Terminal Output
Inside that folder (verified by copying and pasting the URI into explorer) are two files:
default.json
test.json
Config folder contents
That seems to be correct to me, I've checked the guidance and can't see anything out, checked google hits and the answers don't appear to relate. Any help would be greatly appreciated.
Though the mentioned package in the accepted answer resolves the issue, it is good not to get more dependencies in your project's package.json when the same can be sorted with a simple tweak as below: -
In your package.json file by omitting the space before &&. This will detect the environment(s) correctly without extra space after the name.
Quick answer:
Use something like cross-env on windows environments: npm cross-env
From what I can find, this appears to fall into the 'Windows issues with NODE_ENV' category. Setting the NODE_ENV separately, prior to starting the app results in the environment working correctly; any manipulation of NODE_ENV inside a package.json script on its own results in failure.
This answer on another question led me to the package cross-env, and when implemented as identified in the answer resolves the issue.
If anyone else has the same error be sure to run the jest command from your project's root directory if you directly use jest cli instead of an npm script