I have been working on creating a new NPM package named notifman
. Here are the steps I took:
- Started by creating the
package.json
:
{
"name": "notifman",
"version": "1.0.5",
"description": "Advanced, Lightweight and Powerful Notification Library For Plain JS",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "npx nodemon index.js"
},
"keywords": [
"notification",
"frontend",
"js",
"plain"
],
"author": "...",
"license": "MIT",
"dependencies": {
"notifman": "^1.0.3"
},
"devDependencies": {
"nodemon": "^2.0.20"
}
}
- Next, I created the
index.js
file:
console.log("hello world");
- After that, I wrote a README.md for the package.
- Then, I thoroughly tested the package in Node.js and it performed well without any issues.
- Initially, I intended for the package to work in the browser, so I made changes to the code in
index.js
as follows:
export default function getRoot() {
return document.getElementById("root");
}
- Later on, I attempted to test the package using import/export syntax like this:
import getRoot from "notifman";
getRoot.textContent = "hello world";
However, I encountered an error message:
Uncaught TypeError: Failed to resolve module specifier "notifman". Relative references must start with either "/", "./", or "../".
Partially Resolved: I managed to make it work by using Webpack, but I am aware that it shouldn't be necessary. I am determined to make it function WITHOUT webpack. Hence, this issue is only partially resolved.