Intillij Debugging - SyntaxError: Cannot use import statement outside a module
This seems similar to some other questions but in their cases they're doing things differently than I.
When trying to debug or run a reactjs project with Intillij I receive the following message on run:
C:\Users\grant\Documents\code\narjetas\src\App.js:1
import logo from './logo.svg';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1084:15)
at Module._compile (node:internal/modules/cjs/loader:1119:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47
I left the debug config to default with:
In vscode I have the following debug config which does work:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
All the code for my react app is in ./src. Apologies - I suspect I'm missing something obvious but it's not clear to me based on the error message what it is.
Please sign in to leave a comment.
You are trying to run React application with Node.js by running node App.js. This is not supposed to work this way - this is a frontend application that has to be run in browser. You need using the JavaScript Debug run configuration with your server URL (http://localhost:3000). Build the app and start the dev server first, then run the JavaScript Debug run configuration with Debug action to open the browser and attach the debugger to your web page. See https://www.jetbrains.com/help/webstorm/react.html#react_running_and_debugging_debug
In hindsight, that is amazingly obvious. I really appreciate your taking the time to answer that for a noob. Been giving myself a massive crash course in frontend dev and it has been a lot to put together but now that you say it... it's one of those "duh" moments.
Thanks again for taking the time to respond. I really appreciate it - you guys are the best.