mrvautin / expressCart

A fully functioning Node.js shopping cart with Stripe, PayPal, Authorize.net, PayWay, Blockonomics, Adyen, Zip and Instore payments.
https://expresscart-demo.markmoffat.com
MIT License
2.26k stars 875 forks source link

Product image upload causes app crash for published version #142

Closed EngMohamedNor closed 4 years ago

EngMohamedNor commented 4 years ago

I've published the app to windows VM , i can upload product image inside the VM using 127.0.0.1:8080 , but when i access the APP from external computer using IP : 2.23.xx.x.x:8080 , everything works except product image upload , it causes app crash

========================================

Error: ENOENT: no such file or directory, open 'C:\Apps\ShoppingAPP\public\uploads\af065f578dffbb7ed76c091e0ad937ab' Emitted 'error' event on ReadStream instance at: at C:\Apps\ShoppingAPP\node_modules\graceful-fs\graceful-fs.js:190:14 at C:\Apps\ShoppingAPP\node_modules\graceful-fs\graceful-fs.js:241:16 at FSReqCallback.oncomplete (fs.js:155:23) { errno: -4058, code: 'ENOENT', syscall: 'open', path: 'C:\Apps\ShoppingAPP\public\uploads\af065f578dffbb7ed76c091e0ad937ab' } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! express-cart@1.1.17 start: node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the express-cart@1.1.17 start 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\Administrator\AppData\Roaming\npm-cache_logs\2020-05-08T10_38_35_131Z-debug.log

==================================================

LOG FILE CONTENTS

0 info it worked if it ends with ok 1 verbose cli [ 1 verbose cli 'C:\Program Files\nodejs\node.exe', 1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js', 1 verbose cli 'start' 1 verbose cli ] 2 info using npm@6.14.4 3 info using node@v12.16.2 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info lifecycle express-cart@1.1.17~prestart: express-cart@1.1.17 6 info lifecycle express-cart@1.1.17~start: express-cart@1.1.17 7 verbose lifecycle express-cart@1.1.17~start: unsafe-perm in lifecycle true 8 verbose lifecycle express-cart@1.1.17~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Apps\ShoppingAPP\node_modules.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Program Files\nodejs\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm;C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\bin;C:\ProgramData\Administrator\GitHubDesktop\bin 9 verbose lifecycle express-cart@1.1.17~start: CWD: C:\Apps\ShoppingAPP 10 silly lifecycle express-cart@1.1.17~start: Args: [ '/d /s /c', 'node app.js' ] 11 silly lifecycle express-cart@1.1.17~start: Returned: code: 1 signal: null 12 info lifecycle express-cart@1.1.17~start: Failed to exec start script 13 verbose stack Error: express-cart@1.1.17 start: node app.js 13 verbose stack Exit status 1 13 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:310:20) 13 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:310:20) 13 verbose stack at maybeClose (internal/child_process.js:1021:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) 14 verbose pkgid express-cart@1.1.17 15 verbose cwd C:\Apps\ShoppingAPP 16 verbose Windows_NT 10.0.17763 17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start" 18 verbose node v12.16.2 19 verbose npm v6.14.4 20 error code ELIFECYCLE 21 error errno 1 22 error express-cart@1.1.17 start: node app.js 22 error Exit status 1 23 error Failed at the express-cart@1.1.17 start script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]

mrvautin commented 4 years ago

Looks like permissions. Make sure the /uploads directory can create new files and directories within it.

robrob-github commented 4 years ago

I have the same issue. I have ensured public/uploads have global rwx permissions and all sub-directories up to root have global r-x on them at least as well

[centos@ip-10-97-13-237 uploads]$ ls -la total 36 drwxrwxrwx. 4 centos centos 154 May 18 09:49 . drwxrwxrwx. 6 centos centos 156 May 2 10:37 .. drwxrwxr-x. 2 centos centos 29 May 18 09:49 5ec2540f39b63e33e7bc0dae drwxrwxr-x. 2 centos centos 36 May 18 09:45 5ec2547a39b63e33e7bc0daf -rw-rw-r--. 1 centos centos 2744 May 2 10:37 expressCart.svg -rw-rw-r--. 1 centos centos 14640 May 2 10:37 logo-admin.png -rw-rw-r--. 1 centos centos 3877 May 2 10:37 logo.png -rw-rw-r--. 1 centos centos 10345 May 2 10:37 placeholder.png [centos@ip-10-97-13-237 uploads]$ [centos@ip-10-97-13-237 uploads]$ [centos@ip-10-97-13-237 uploads]$ pwd /home/centos/expressCart-master/public/uploads

Console output: GET /admin/product/edit/5ec2540f39b63e33e7bc0dae 200 32.196 ms - 31004 GET /stylesheets/pushy.min.css 304 14.687 ms - - GET /stylesheets/admin.min.css 304 8.101 ms - - GET /stylesheets/codemirror-style.min.css 304 10.122 ms - - GET /javascripts/jquery.bootpag.min.js 304 7.322 ms - - GET /stylesheets/style.min.css 304 9.912 ms - - GET /javascripts/cssbeautify.min.js 304 2.994 ms - - GET /javascripts/common.min.js 304 9.139 ms - - GET /javascripts/expressCart.min.js 304 9.284 ms - - GET /javascripts/admin.min.js 304 9.360 ms - - GET /images/logo-admin.png 304 8.955 ms - - GET /javascripts/pushy.min.js 304 6.980 ms - - GET /dist/feather-sprite.svg 304 3.143 ms - - events.js:174 throw er; // Unhandled 'error' event ^

Error: ENOENT: no such file or directory, open 'public/uploads/c2a197ae1444da5fb131578c9859ef4c' Emitted 'error' event at: at lazyFs.open (internal/fs/streams.js:115:12) at FSReqWrap.args [as oncomplete] (fs.js:140:20) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! express-cart@1.1.18 start: node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the express-cart@1.1.18 start 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/centos/.npm/_logs/2020-05-18T09_49_00_063Z-debug.log

(Note the directory name from the ENOENT differs from that in the public/uploads directory)

mrvautin commented 4 years ago

I'm 100% sure this is permissions. @robrob-github Can you try a test by running the app as root to see if the error persists?

EngMohamedNor commented 4 years ago

@mrvautin i was running on Amazon EC2 windows vm , and give full permission to the uploads folder , the strange thing is that image upload works when i access the app with localhost , but crashes when i access with vm public IP from other pc.

mrvautin commented 4 years ago

@EngMohamedNor Could that be related to user running the Webserver (IIS on windows - App Pool?) not having permission to the folder? I'm not familiar with Windows but from memory IIS user permissions requires some tweaking.

Running an application as localhost and serving from a Webserver are two very different things permission wise.

EngMohamedNor commented 4 years ago

@mrvautin I'm not using IIS directly , IIS is running on port 80 and i am running the app on 8080 , installed Node and started the app with command prompt , don't know how IIS can affect based on my configuration. i thought express was enough . it's my first experience hosting Node app on windows

mrvautin commented 4 years ago

You already have more experience than me running Nodejs on Windows! 😀I've not tried it before.

Did you get it working in the end?

EngMohamedNor commented 4 years ago

@mrvautin everything else is working , will try to spend sometime on this ...

nomadcult commented 4 years ago

@mrvautin @EngMohamedNor @robrob-github

I can confirm the same. I use docker with nginx as reverse proxy on aws. Did the usual troubleshooting and research.

I have tried different browsers (to see if browsers trigger it (content length)). Tried different node versions. Hacked around with the admin route a bit.

The result is same. The app crashes as it can't find the uploaded file.

The store front has no (broken images). This is fucking strange as it should not happen.

It could be cors, it could be proxy header issues, it could be something else, it could be the fs/fsevent package issue or any other dependent module issue ...

Ping back here if you need more info

GET /admin/orders 302 10.202 ms - 68 GET /admin/login 200 167.660 ms - 11927 POST /admin/login_action 200 136.798 ms - 30 GET /admin 302 7.939 ms - 76 GET /admin/dashboard 200 95.099 ms - 25435 GET /admin/products 200 70.709 ms - 27252 GET /admin/product/new 200 76.882 ms - 27361

Error: ENOENT: no such file or directory, open 'public/uploads/03fdb92763542461d502f1a4aaeb8c34' Emitted 'error' event on ReadStream instance at: at internal/fs/streams.js:132:14 at FSReqCallback.oncomplete (fs.js:146:23) { errno: -2, code: 'ENOENT', syscall: 'open', path: 'public/uploads/03fdb92763542461d502f1a4aaeb8c34' } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! express-cart@1.1.18 start: node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the express-cart@1.1.18 start 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! /root/.npm/_logs/2020-05-21T21_30_43_835Z-debug.log

docker build: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/glob-watcher/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})


0 info it worked if it ends with ok 1 warn npm npm does not support Node.js v13.0.0 2 warn npm You should probably upgrade to a newer version of node as we 3 warn npm can't make any promises that npm will work with this version. 4 warn npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12. 5 warn npm You can find the latest version at https://nodejs.org/ 6 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ] 7 info using npm@6.12.0 8 info using node@v13.0.0 9 verbose run-script [ 'prestart', 'start', 'poststart' ] 10 info lifecycle express-cart@1.1.18~prestart: express-cart@1.1.18 11 info lifecycle express-cart@1.1.18~start: express-cart@1.1.18 12 verbose lifecycle express-cart@1.1.18~start: unsafe-perm in lifecycle true 13 verbose lifecycle express-cart@1.1.18~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/expressCart/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/u sr/bin:/sbin:/bin 14 verbose lifecycle express-cart@1.1.18~start: CWD: /var/expressCart 15 silly lifecycle express-cart@1.1.18~start: Args: [ '-c', 'node app.js' ] 16 silly lifecycle express-cart@1.1.18~start: Returned: code: 1 signal: null 17 info lifecycle express-cart@1.1.18~start: Failed to exec start script 18 verbose stack Error: express-cart@1.1.18 start: node app.js 18 verbose stack Exit status 1 18 verbose stack at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 18 verbose stack at EventEmitter.emit (events.js:210:5) 18 verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 18 verbose stack at ChildProcess.emit (events.js:210:5) 18 verbose stack at maybeClose (internal/child_process.js:1028:16) 18 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) 19 verbose pkgid express-cart@1.1.18 20 verbose cwd /var/expressCart 21 verbose Linux 5.6.13-232.aws 22 verbose argv "/usr/bin/node" "/usr/bin/npm" "start" 23 verbose node v13.0.0 24 verbose npm v6.12.0 25 error code ELIFECYCLE 26 error errno 1 27 error express-cart@1.1.18 start: node app.js 27 error Exit status 1 28 error Failed at the express-cart@1.1.18 start script. 28 error This is probably not a problem with npm. There is likely additional logging output above. 29 verbose exit [ 1, true ]


From Chrome Dev tools: A cookie associated with a cross-site resource at http://cloudflare.com/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.

Uncaught TypeError: Cannot read property 'message' of undefined at Object. (admin.js:766) at c (jquery.min.js:2) at Object.fireWith [as rejectWith] (jquery.min.js:2) at l (jquery.min.js:2) at XMLHttpRequest. (jquery.min.js:2)

jquery.min.js:2 POST https://store.mysite.com/admin/file/upload net::ERR_HTTP2_PROTOCOL_ERROR 200 jquery.min.js:2 POST https://store.mysite.com/admin/file/upload 502

200 and 502 keeps changing depending on if server crashed and restarted

Nginx conf:

server { server_name store.mysite.com; listen 0.0.0.0:443 ssl http2; ssl_certificate /etc/nginx/certs/mysitecert.pem; ssl_certificate_key /etc/nginx/certs/mysitekey.pem; ssl_client_certificate /etc/nginx/certs/cloudflare.crt; ssl_verify_client on; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://ecart:1111; } client_max_body_size 5M; }

nomadcult commented 4 years ago

Everything else is working. One thing is that the menu doesn't appear.

nomadcult commented 4 years ago

If anyone has a working docker + nginx config, please share

mrvautin commented 4 years ago

@nomadcult I've tested using Docker locally and its working fine. Seems to be related to AWS only. Is there specific permissions you need to set in AWS to write files to the /uploads directory? Can you give me more info on your AWS deployment so I can try replicate?

nomadcult commented 4 years ago

@mrvautin

Please see my config: https://gist.github.com/nomadcult/3fc2ed3f768d813f27336892b8664ddf

That helps you replicate on aws.

I use clear linux on aws.

nomadcult commented 4 years ago

This issue somehow persists

mrvautin commented 4 years ago

I'm no Docker expert but I just spun up a server on Digital Ocean, ran the steps in the readme (docker-compose up --build) with the default Dockerfile and everything works fine. Tested uploads and working correctly.

It looks like something specific to AWS. Can you try asking their support/forums?

mrvautin commented 4 years ago

@nomadcult I've made some small changes to the handling of uploads. Not sure if it will resolve your issues or not. Can you please test the latest master?

mrvautin commented 4 years ago

Closing issue due to inactivity. Can reopen if required.