Scenario : I recently started using the Editor.js library for a personal project
Editor.js documentation
Here is the structure of my project directory :
https://i.sstatic.net/4lkJE.png
Check out the contents of my package.json file :
{
"name": "quicknoteapp",
"version": "1.0.0",
"description": "",
"main": "myApp.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"@editorjs/editorjs": "^2.19.0",
"electron": "^10.1.5",
"menubar": "^9.0.1"
}
}
The code snippet from my index.html
:
<script type="module" src="main.js"></script>
I'm importing the EditorJS library from my main.js
file :
import EditorJS from '@editorjs/editorjs';
However, I encountered an error in the console that says :
TypeError: Module specifier, '@editorjs/editorjs' does not start with "/", "./", or "../". Referenced from file:///Users/charles/Desktop/QuickNoteApp/main.js
It seems like I need to specify the relative path when importing the module. But why do I have to do this? Why can't I follow the same approach as mentioned in the documentation? What am I missing during the project setup process? It doesn't seem right to manually add paths for each script. If not, then what's the purpose of using npm and having a node_module folder.