I know there are a couple of similar questions about declaration files but none of them could help me fix my problem. First of all I am going to explain why I am trying to do this. If you just want to read the actual problem start reading further down.
I am fairly new to programming and started going to programming school a few months ago. Lately we have learned to create websites with HTML/CSS and JavaScript and our teacher now wants us to learn how to make desktop apps in JavaScript using Node.js and electron. He gave us the homework to make a hardware monitor and find modules or frameworks that could help us. So far we have only been using standard JavaScript without any frameworks, so this is new to me.
Problem: So I found out that Node.js provides the os module which helps you access a lot of hardware and system stuff, but doesn't help you fetch information about your harddrives. Then I Googled and found drivelist: https://www.npmjs.com/package/drivelist
I also found a short tutorial on how to install and use it. I installed it via npm install drivelist
and used sample code from said website, but I get the following message when hovering over const drivelist = require('drivelist');
:
"Could not find a declaration file for module 'drivelist'.
'c:/Users/user.name/Documents/source/Projektarbeit/node_modules/drivelist/lib/drivelist.js'
implicitly has an 'any' type. Try `npm install @types/drivelist` if
it exists or add a new declaration (.d.ts) file containing `declare
module 'drivelist';` [7016]"
I checked out the folders and there is a drivelist.js in the lib folder. I tried to run npm install @types/drivelist
but it gave me another error:
npm ERR! code E404
npm ERR! 404 Not Found: @types/drivelist@latest
And I get the following message when executing my file:
Uncaught Error: A dynamic link library (DLL) initialization routine
failed.
\\?\C:\Users\user.name\Documents\source\Projektarbeit\node_modules\drivelist\build\Release\drivelist.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (internal/modules/cjs/loader.js:620)
at tryModuleLoad (internal/modules/cjs/loader.js:559)
at Function.Module._load (internal/modules/cjs/loader.js:551)
at Module.require (internal/modules/cjs/loader.js:658)
at require (internal/modules/cjs/helpers.js:20)
at bindings (C:\Users\user.name\Documents\source\Projektarbeit\node_modules\bindings\bindings.js:84)
at Object.exports.list (C:\Users\user.name\Documents\source\Projektarbeit\node_modules\drivelist\lib\drivelist.js:52)
Here are all my project files and their contents:
package.json:
{
"name": "projektarbeit",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"drivelist": "^6.4.3"
}
}
main.js:
const { app, BrowserWindow } = require('electron')
function createWindow () {
win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
app.on('ready', createWindow)
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="scripts\index.js"></script>
</head>
<body>
</body>
</html>
index.js:
const drivelist = require('drivelist');
drivelist.list((error, drives) => {
if (error) {
throw error;
}
drives.forEach((drive) => {
console.log(drive);
});
});
I know this is probably a pretty noob question but I have tried fixing and Googling for an hour now and only found stuff that did not solve my problem.
I also don't know what this advice really wants me to do: "add a new declaration (.d.ts) file containing declare module 'drivelist';
[7016]"