Rinkusu – 04-39 Jan 29

Even after "npm init", "npm i fs" and adding "type": "module" I keep getting "Cannot use import statement outside a module". Any idea please ?
UU
Unknown User810d ago
L
LaRynk810d ago
require is not defined
UU
Unknown User810d ago
L
LaRynk810d ago
I don't know if I did it right. It is just a JS project (dir with css, html and js files) that I tried to turn into node.js so I can use fs with chrome (live server extension of vs code)
UU
Unknown User810d ago
L
LaRynk810d ago
you mean node packages ? I did a lot of React and never had any issue like this
UU
Unknown User810d ago
L
LaRynk810d ago
how do I do that ? (I just want to modify a local json file)
UU
Unknown User810d ago
L
LaRynk810d ago
require is not defined
UU
Unknown User810d ago
L
LaRynk810d ago
v14.17.0
UU
Unknown User810d ago
L
LaRynk810d ago
done
UU
Unknown User810d ago
L
LaRynk810d ago
no I meant already done
UU
Unknown User810d ago
L
LaRynk810d ago
let fs = require('fs')
let data = fs.readFileSync('./list.json')
console.log(data)
let fs = require('fs')
let data = fs.readFileSync('./list.json')
console.log(data)
UU
Unknown User810d ago
L
LaRynk810d ago
{
"name": "mini-projects-hub",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "",
"license": "ISC",
"dependencies": {
"fs": "0.0.1-security"
}
}
{
"name": "mini-projects-hub",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "",
"license": "ISC",
"dependencies": {
"fs": "0.0.1-security"
}
}
UU
Unknown User810d ago
L
LaRynk810d ago
Cannot use import statement outside a module I'm retrying with the line in package.json got
<Buffer 7b 0d 0a 20 20 22 70 72 6f 6a 65 63 74 73 22 3a 20 5b 0d 0a 20 20 20 20 7b 20 22 74 69 74 6c 65 22 3a 20 22 73 74 6f 70 77 61 74 63 68 22 2c 20 22 72 ... 401 more bytes>
<Buffer 7b 0d 0a 20 20 22 70 72 6f 6a 65 63 74 73 22 3a 20 5b 0d 0a 20 20 20 20 7b 20 22 74 69 74 6c 65 22 3a 20 22 73 74 6f 70 77 61 74 63 68 22 2c 20 22 72 ... 401 more bytes>
UU
Unknown User810d ago
L
LaRynk810d ago
ok, I got my data back but how do I run the html page and the file with node at the "same time" or something like that You said I don't neet to install it, u meant the npm i fs ?
UU
Unknown User810d ago
L
LaRynk810d ago
yeah I know, but I want to modify it from the html page
UU
Unknown User810d ago
L
LaRynk810d ago
i used xhr ok I got it now, sry you already told me I thought node was a solution
UU
Unknown User810d ago
L
LaRynk810d ago
ok thx a lot for your time even if I don't think I'll make a back for this 😅
UU
Unknown User810d ago