Having Trouble Importing My NPM Package Using ES6 Import/Export Syntax

I have been working on creating a new NPM package named notifman. Here are the steps I took:

  1. 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"
  }
}
  1. Next, I created the index.js file:
console.log("hello world");
  1. After that, I wrote a README.md for the package.
  2. Then, I thoroughly tested the package in Node.js and it performed well without any issues.
  3. 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");
}
  1. 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.

Answer №1

"category": "module"

**include the following line in your package.json right after main **

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ESLint encountered an issue while attempting to load the configuration "plugin:@angular-eslint/ng-cli-compat" for extension

After attempting to upgrade my Angular project from version 15 to 16, I am now facing a series of perplexing errors. IntelliJ is displaying the following error at the top: https://i.stack.imgur.com/nCS2M.png Furthermore, when trying to run ng serve, it f ...

Connecting the input[date] and Moment.js in AngularJS

For the purpose of formulating a question, I have prepared a simplified example: ... <input type="date" ng-model="selectedMoment" /> ... <script> angular.module('dateInputExample', []) .controller('DateController', [& ...

Switch out HTML dynamically using JavaScript/JQuery, embracing the principles of DRY coding

As a newcomer to front-end development, one issue I frequently encounter is avoiding repetition when dynamically generating HTML using JS/jQuery. Imagine you have a DOM object that has various states. Typically, all you need to do with JS is switch betwee ...

The radial gradient in d3.js does not properly affect paths

My goal is to create a radial gradient on my path element, but for some reason the radial gradient does not apply correctly. Can anyone help me troubleshoot this issue? Below is my updated code: // Define the canvas / graph dimensions var margin = {top: ...

Display data fetched from concurrent Ajax calls in a React Component

I am currently in the process of converting my original project to Reactjs. Since I am new to this and it's my first application, I could use some guidance on how to effectively implement this in a React-friendly way and enhance both my skills and the ...

Troubleshooting issue with Rails 5.2.3 AJAX request: JSON key-value pairs containing the plus sign are not being received

In my Rails 5.2.3 project, I am attempting to send an AJAX request that includes a JSON representation of a callflow object (the specifics of which are not relevant). This JSON representation is located within a textarea with the id "newCallflowJsonDisplay ...

Tips for Sending Information to the Current Page Using JQuery

I am attempting to send the form data back to the same location as the form itself. The code needs to: Trigger the click action for #submit Retrieve data from #email, #selection1, and #selection2 Hide the form #form Show the data in #email, #selection1, ...

Displaying JSON data from the API on a webpage within a NodeJS weather application

Currently, I am in the process of developing a weather application using NodeJS. I have successfully retrieved JSON formatted data from the weather site's API. Nonetheless, I am perplexed about how to transmit this data to the application. Below is a ...

What drawbacks come with developing an Express.js application using TypeScript?

Curious about the potential drawbacks of using TypeScript to write Express.js applications or APIs instead of JavaScript. ...

Having issues compiling VUE.JS using the 'npm run dev' and 'npm run watch' commands

I've inherited a project that's already been developed by someone else. Everything seems to be in working order, but I need to make some changes to the Vue code. However, when I try to run the 'npm run dev' or 'watch' command ...

How to Assign a Specific ID to the Body Tag in Wordpress Using functions.php

Struggling to find a simple solution after scouring the web for answers. Most tutorials are overly complicated. I'm attempting to integrate a jQuery menu system into my Wordpress site and want to assign a unique body ID to make targeting easier. I p ...

Listener for body keystrokes

Is there a way to trigger a function when the space bar is pressed on the page, without it being called if an input field is focused? Any thoughts or suggestions? The current code triggers the function even when an input bar is focused: $(document).keydo ...

Grunt: Executing tasks exclusively for updated files - the ultimate guide!

In my Gruntfile.js, I have the configuration set up as follows: module.exports = function(grunt) { require('jit-grunt')(grunt); grunt.initConfig({ uglify: { options: { manage: false }, my_target: { file ...

Display a page with sections that have opacity applied, identified by the hashtag #section, and utilize JavaScript to automatically scroll to the top of

Check out my app at . I'm working on overriding the scroll bar behavior in CSS to keep the entire app visible, including the logo, header, and controls, as users navigate through different sections. However, I seem to be having trouble with the CSS as ...

When navigating to '/blogs/', the index.js file in Next.js will automatically open

I'm working on a project using next.js and I want to ensure that when I visit 'localhost:3000/blogs/', it opens the index.js page. The index.js file is located in the 'blogs' folder of my project. Currently, it does open properly ...

How can I utilize the mapv tool created by Baidu in a Node project?

I need assistance converting the following code to a node environment. The code can be found at Here is the code snippet: var map = new BMap.Map(slice.selector, { enableMapClick: false }); // Create Map instance map.centerAndZoom( ...

Working with Grunt in VS Code: Running Grunt tasks from the node_modules.bin

I've been experimenting with Visual Studio Code, Node.js, and Grunt, but I'm running into some issues. It appears that VS Code is not able to execute grunt from the local node_modules\.bin directory where npm installs it. While everything wo ...

The setInterval() function is not executing the IF Else statement correctly

I'm having an issue with accessing if else conditions. Currently, both the if block and else block are being called at the same time. I need help in making the if else block work properly. Here is a snippet of my code: const UserCard=(props)=>{ c ...

Is there a way to incorporate a trace in Plotly while also arranging each data point along the x-axis in a unique custom order?

I am facing a challenge in creating a line graph that displays (x, y) coordinates where the x axis represents a date and the y axis represents a value. The dates are formatted like DD-MM-YYYY, for example, 15-04-2015. My initial trace is added with the fo ...

What is the method to select a hyperlink that includes a variable in the "href" attribute and click on it?

Currently, I am in the process of creating acceptance tests utilizing Selenium and WebdriverIO. However, I have encountered a problem where I am unable to successfully click on a specific link. client.click('a[href=#admin/'+ transactionId + &apo ...