SyntaxError: Cannot use import statement outside a module

SyntaxError: Cannot use import statement outside a module

Image for post[nodemon] starting `node server.js`Debugger listening on ws://127.0.0.1:60427/65843c3d-fa9c-4824-ae93-11ca007819d8For help, see: https://nodejs.org/en/docs/inspector[nodemon] restarting due to changes…[nodemon] starting `node server.js`Debugger listening on ws://127.0.0.1:60428/5a396055-dbbd-419c-879c-47378401e182For help, see: https://nodejs.org/en/docs/inspectorDebugger attached.(node:11959) Warning: To load an ES module, set “type”: “module” in the package.json or use the .mjs extension.(Use `node –trace-warnings …` to show where the warning was created)Waiting for the debugger to disconnect…/Users/fredriccliver/Projects/todoListApi/server.js:1import express from ‘express’^^^^^^SyntaxError: Cannot use import statement outside a module at wrapSafe (internal/modules/cjs/loader.js:1116:16) at Module._compile (internal/modules/cjs/loader.js:1164:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10) at Module.load (internal/modules/cjs/loader.js:1049:32) at Function.Module._load (internal/modules/cjs/loader.js:937:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47[nodemon] app crashed – waiting for file changes before starting…

add this line into your package.json

…”type”: “module”,…

https://nodejs.org/api/esm.html#esm_package_json_type_field

No Responses

Write a response