LaRynk
LaRynkβ€’3y ago

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 ?
32 Replies
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
require is not defined
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y 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)
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
you mean node packages ? I did a lot of React and never had any issue like this
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
how do I do that ? (I just want to modify a local json file)
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
require is not defined
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
v14.17.0
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
done
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
no I meant already done
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y 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)
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y 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"
}
}
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y 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>
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y 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 ?
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
yeah I know, but I want to modify it from the html page
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
i used xhr ok I got it now, sry you already told me I thought node was a solution
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
LaRynk
LaRynkβ€’3y ago
ok thx a lot for your time even if I don't think I'll make a back for this πŸ˜…
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibotβ€’3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/936842902624157708