I use nodejs to run js files in command prompt.
When I ran import.js by typing
node import.js
in command prompt it says " (node:2952) 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)" and "
import { uppercaseString, lowercaseString } from ‘./export.js’; ^^^^^^
SyntaxError: Cannot use import statement outside a module" and as you can see I use console.log() in import.js so the output should be
HELLO world!
I also tried it in a html file too and nothing shows up.
Thanks… I found the package.json file under C:\Program Files\nodejs and tried to add
“type”: “module”
and it said I don’t have access or something like that so I copied all the code in package.json file and created a new file called package.json with code added
“type”: “module”
under the folder I put my js files (export.js, import.js …) and it worked. I’m a bit confused I mean there’s two package.json files … however it worked the code worked.
THANKS!
It’s a good idea to think in projects.
One project lives in one project folder.
So this means that each project has its own package.json in its own project folder.