Hello i am running Ubuntu server on "digitalocean" but getting error when trying to run my app using pm2 start App.js
at first it shows as its online but ones you pm2 list
its says errored and in the logs you can see error
/var/www/project/src/index.js:1 0|src | import React from 'react'; 0|src | ^^^^^^ 0|src | 0|src | SyntaxError: Cannot use import statement outside a module 0|src | at wrapSafe (internal/modules/cjs/loader.js:1001:16) 0|src | at Module._compile (internal/modules/cjs/loader.js:1049:27) 0|src | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) 0|src | at Module.load (internal/modules/cjs/loader.js:950:32) 0|src | at Function.Module._load (internal/modules/cjs/loader.js:790:12) 0|src | at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23) 0|src | at Module._compile (internal/modules/cjs/loader.js:1085:14) 0|src | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) 0|src | at Module.load (internal/modules/cjs/loader.js:950:32) 0|src | at Function.Module._load (internal/modules/cjs/loader.js:790:12)
Asked
Active
Viewed 275 times
0

John
- 1
- 1
-
add "type": "module" in your package.json – kavigun Sep 13 '22 at 19:48
-
It removed `var/www/project/src/index.js:1 0|src | import React from 'react'; 0|src | ^^^^^^ 0|src | 0|src` but the rest still there, and there is actually new error ` SyntaxError: Unexpected token '<' ` – John Sep 13 '22 at 21:07
-
convert .js files to .mjs OR else instead of import do require to load the module in js file – kavigun Sep 14 '22 at 05:42